Reputation: 1429
I have a question about property in Swift.
Does get{} and set{} only support the computed properties?
var name: String {
get {
// return something
}
set {
// do something
}
}
Upvotes: 0
Views: 110
Reputation: 385500
Your question is still unclear (even though you added the missing verb). Nevertheless I'll try to answer it:
Only computed properties may have get
and set
blocks. That is what makes them “computed”.
The opposite of a computed property is a “stored” property. (The language reference calls this a “stored variable property”.) A stored property cannot have get
and set
blocks.
You can observe changes to stored properties, and to inherited properties of any kind, by defining willSet
and didSet
blocks for them.
Many details are spelled out in “Properties” in The Swift Programming Language. You can also search for “Properties” in the “Declarations” section of language reference. (Interior links into the language reference don't work as of this writing.)
Upvotes: 2