简体   繁体   中英

Xcode 7 beta 5 Swift 2 redundant conformance to protocol error

I recently download Xcode 7 which comes with Swift 2. Below is the error I get when I try to conform my class to UITableViewDataSource and UITableViewDelegate which works perfectly well in Xcode 6.2 but throws an error in Xcode 7 beta 5

class TableViewController: UITableViewController, UITableViewDataSource, UITableViewDelegate {
}

//error: Redundant conformance of 'TableViewcontroller' to protocol 'UITableViewDataSource'

I have searched google for answers but I couldn't get a fix for it.

There is no need to indicate that you TableViewController conforms to the two protocols because the UITableViewController already does. So your class will as well due to the inheritance.

All you need is:

class TableViewController: UITableViewController {
}

It seems Swift2 is more strict about this than Swift is.

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