swift - 无法在类实例中调用函数

标签 swift

我有一个类 DiscoverUserInfo,它有一个函数 compoundKeyValue。我需要在第 23 行调用这个函数(见下图)。但是我收到以下错误:

Value of type '(NSObject) -> () -> DiscoverUserInfo' has no member 'compoundKeyValue'

enter image description here

最佳答案

self 初始化期间,您不能调用 self 上的方法。也许您想创建一个计算属性?

public var compoundKey: String {
    return self.compoundKeyValue
}

这还允许您从 UserObject 中删除 didSet 处理程序。

关于swift - 无法在类实例中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42610184/

相关文章:

ios - Unwind segue 使用 Swift 隐藏 UITabBar

ios - 如何使用 UIContainerView 在 iPad 上隐藏 UISplitViewController master 上嵌入的辅助 UITableViewController 的 DetailView

ios - 应用程序在后台时未收到 Swift FCM 数据消息 (iOS 10)

swift - 计时器计数但不显示

swift - 将我的代码变成更好的类似 Swift 的 FizzBu​​zz 响应答案

ios - fatal error : Unexpectedly found nil while unwrapping an Optional value while loading webView

ios - 如何在 Delegate 中引用其他 ViewController 而不仅仅是 root

ios - 尝试将 PFObject 连接到下一个 View Controller 时出错(Swift 1.2)

json - POST 请求后在 swift 模型中访问值的问题

ios - 有没有办法在iOS中生成Int64类型的UUID?