ios - 类不符合协议(protocol)

标签 ios swift oop

这是我的协议(protocol):

protocol LiveTableViewCellProtocol: class {
    var data: LiveCellObjectProtocol! { get set }
}

这是我的课:

class RepliesTableViewCell: UITableViewCell, LiveTableViewCellProtocol {
        var data: RepliesCellObject! //ERROR! does not conform to protocol.
}

RepliesCellObject 定义为:

public class RepliesCellObject: NSObject , LiveCellObjectProtocol{
    //basic stuff here.
}

RepliesCellObject 是一个 LiveCellObjectProtocol ...那么为什么我的表格单元格不符合要求?

最佳答案

它不符合,因为在符合 LiveTableViewCellProtocol 的对象中,您可以将数据设置为任何 LiveCellObjectProtocol,包括非 NSObject 的数据。在 RepliesTableViewCell 中,您不能这样做。数据必须设置为 LiveCellObjectProtocol,它也是一个 NSObject。

因此 RepliesTableViewCell 不符合 LiveTableViewCellProtocol。

关于ios - 类不符合协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38317051/

相关文章:

c++ - 为什么我们需要抽象类而不是虚拟类?

oop - 如何将 Haskell 类型类转换为 F#?

ios - 当我们从 AppSTore 下载应用程序或更新时,iOS 会调用哪些 API

ios - 在另一个 Controller 中调用 viewDidLoad

ios - 如何在 Swift 中使用 UIDatePicker 仅在没有日期组件的情况下将时间存储在 CoreData 中?

php - 使用php获取父文件夹路径

ios - 如何在IOS中实现输入文本框作为必填字段

ios - 在 Swift 中执行后台保存

ios - 未从 Firebase 收到通知

ios - Swift didReceiveRemoteNotification userInfo 无法获取值