Reputation:
Take a look at this variable
var username: String {
get {
return self.twitterAccount.valueForKey("username") as! String
}
}
The compiler doesn't complain when I remove the get, presumably because it is simply treated as a computed property.
var username: String {
return self.twitterAccount.valueForKey("username") as! String
}
What would warrant using one of these approaches over the other ?
Upvotes: 2
Views: 77
Reputation: 13243
If you only have a getter you can do this simplification. But if you also have a setter you have to use the former version in order to separate both.
Upvotes: 1
Reputation: 285069
Both forms are exactly the same thing, a read-only computed property.
From the documentation:
You can simplify the declaration of a read-only computed property by removing the get keyword and its braces.
Upvotes: 3