Since upgrading on Xcode 8 (Beta 1) and Swift 3 I have an error in this line:
class CloudViewController: UIViewController, WCSessionDelegate {
It says :
Type 'UIViewController' does not conform to protocol 'WCSessionDelegate'
This is my (with Xcode 7 and Swift 2 working) code:
override func viewDidLoad() {
super.viewDidLoad()
if(WCSession.isSupported()){
self.session = WCSession.default()
self.session.delegate = self
self.session.activate()
}
}
func session(_ session: WCSession, didReceiveMessage message: [String : AnyObject]) {
print("didReceiveMessage")
watchMessageHandler.getMessage(message)
}
This error also shows up in the WKInterfaceController classes.
Every protocol comes with a set of methods that you are supposed to implement in order to conform to them. You must write those methods in your class to conform to it.
For example, in a UIViewController, if you decide to have a tableView, you must add the UITableViewDataSource
, UITableViewDelegate
protocol, like so:
class ViewController : UIViewController, UITableViewDataSource, UITableViewDelegate {
}
But, this is not complete implementation of the protocol. This is mere declaration.
To actually have your View Controller conform to the protocol, you will have to implement two methods, namely: cellForRowAtIndexPath
andnumberOfRowsInSection
. This is the requirement of the protocol.
So, the complete implementation would look something like:
class ViewController : UIViewController, UITableViewDataSource, UITableViewDelegate {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellID", forIndexPath: indexPath) as! ExperienceCell
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
}
Therefore, you must look into the documentation and find what methods does your protocol require the class to implement. That should solve this problem. And I don't think it is to do anything with Xcode 8 or swift 3
EDIT Here: This is what apple documentation says
Most methods of this protocol are optional. You implement the methods you need to respond to the data transfer operations that your apps support. However, apps should implement support for the session:activationDidCompleteWithState:error: method to support asynchronous activation, and the delegate in your iPhone app should implement the sessionDidBecomeInactive: and sessionDidDeactivate: methods to support multiple Apple Watches.