斯威夫特:为什么"()"关闭后需要"() - >"在类型之前缺少?

时间:2017-01-24 15:52:54

标签: swift closures

下一个代码是正确的,但我不明白 为什么"()"关闭后需要, if"() - >"在输入之前丢失了吗?

class Person {
    var name: String
    /*lazy var personalizedGreeting: ()->String = {
        [unowned self] in
        return "Hello, \(self.name)!"
    }*/
    lazy var personalizedGreeting: String = {
        [unowned self] in
        return "Hello, \(self.name)!"
        }()
    init(name: String) {
        self.name = name
    }
}
let person = Person(name: "John Doe")
print(person.personalizedGreeting)

0 个答案:

没有答案