简体   繁体   中英

Implementing Protocol In Generic class in swift

Let say I want to make Class TableViewDataSourceImpl like this :

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 {

     }
}

then xcode show me error type 'TableViewDataSource<T,U>' does not conform to protocol 'UITableViewDataSource'

is this a bug in xcode? or swift cannot make class with generic that implement protocol? because I gonna make tableView.datasource = tableViewDataSource

i know that we cant convert our swift generic into objective-c, but I not gonna use any objective-c here

I do this in xcode 7 beta 1

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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