错误"类型的值...没有成员"在懒惰的财产关闭中调用自我

时间:2017-01-11 02:05:20

标签: swift3 xcode8

为什么以下Swift3代码在Xcode 8中导致错误value of type (NSObject) -> () -> MyView has no member getSomeButton

lazy var someButton = {
    return self.getSomeButton // ERROR
}()

private func getSomeButton() -> UIButton {
    return UIButton()
}

1 个答案:

答案 0 :(得分:1)

实际上,错误消息完全是误导性的,应该是can't infer closure return type。指定变量类型可以解决问题。希望这有助于某人。

lazy var someButton: UIButton = {
    return self.getSomeButton // OK
}()