【问题标题】:Implementing Protocol In Generic class in swift快速在通用类中实现协议
【发布时间】:2015-06-26 05:13:50
【问题描述】:

假设我想像这样创建TableViewDataSourceImpl 类:

class TableViewDataSourceImpl<T, U: UITableViewCell where U: ReusableCell>:NSObject, UITableViewDataSource {

     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

     }
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

     }
}

然后 xcode 显示错误type 'TableViewDataSource&lt;T,U&gt;' does not conform to protocol 'UITableViewDataSource'

这是 xcode 中的错误吗?或者 swift 不能使用实现协议的泛型类?因为我要做tableView.datasource = tableViewDataSource

我知道我们不能将 swift 泛型转换为 Objective-c,但我不会在这里使用任何 Objective-c

我在 xcode 7 beta 1 中这样做

【问题讨论】:

    标签: ios xcode generics swift2


    【解决方案1】:

    只需将我的 xcode 更新到 beta 2 即可!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      相关资源
      最近更新 更多