繁体   English   中英

快速实现泛型类中的协议

[英]Implementing Protocol In Generic class in swift

假设我要使Class 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<T,U>' does not conform to protocol 'UITableViewDataSource'

这是xcode中的错误吗? 或迅速无法使用实现协议的泛型创建类? 因为我要使tableView.datasource = tableViewDataSource

我知道我们无法将Swift泛型转换为Objective-C,但我不会在这里使用任何Objective-C

我在xcode 7 beta 1中执行此操作

只需将我的xcode更新为beta 2,它就可以工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM