Getter vs Computed property. What would warrant using one of these approaches over the other?

前端 未结 2 989
我在风中等你
我在风中等你 2020-12-21 16:14

Take a look at this variable

var username: String {
    get {
        return self.twitterAccount.valueForKey(\"username\") as! String
    }
}
2条回答
  •  轮回少年
    2020-12-21 17:14

    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.

提交回复
热议问题