簡體   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