2016-06-18 11 views
3

のXcode 8(ベータ1)とスウィフト3にアップグレードしたので、私は、この行でエラーを持っている:タイプ 'のUIViewController' プロトコルに準拠していない 'WCSessionDelegate'

class CloudViewController: UIViewController, WCSessionDelegate { 

それは言う:

Type 'UIViewController' does not conform to protocol 'WCSessionDelegate'

は、これは私の(Xcodeの7とスウィフト2の作業との)コードは:

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) 

} 

も、このエラーがWKInterfaceControllerクラスに表示されます。

+0

あなたはプロジェクトをビルドしましたか? –

+0

@AkshanshThakurはい、複数回 – Devhess

+0

ビルド出力の完全なエラーを読むと、プロトコルに準拠していないことがわかります –

答えて

6

すべてのプロトコルには、それらに準拠するために実装する必要がある一連のメソッドが付属しています。クラスに準拠するようにそれらのメソッドを記述する必要があります。これは、プロトコルの完全な実装ではありません、

class ViewController : UIViewController, UITableViewDataSource, UITableViewDelegate { 

} 

をしかし:あなたはのtableViewを持ってすることを決定した場合

は例えば、のUIViewControllerに、あなたがそうのように、UITableViewDataSourceUITableViewDelegateプロトコルを追加する必要があります。これは単なる宣言です。

実際にView Controllerをプロトコルに準拠させるには、cellForRowAtIndexPathnumberOfRowsInSectionという2つのメソッドを実装する必要があります。これはプロトコルの要件です。

ので、完全な実装は次のようになります。そのため、あなたはドキュメントを調べて、あなたのプロトコルが実装するクラスを必要としないものをする方法を見つける必要があります

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 
    } 

} 

。 これはこの問題を解決するはずです。そして、私はそれがXcodeの8またはSWIFT 3

EDITここで何かをするとは思わない:これは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.

-1

があなたのCloudViewControllerにこのメソッドを追加するものである

internal func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: NSError?){ 
} 

このエラーは、WCSessionDelegateに必要なプロトコルメソッドを実装する必要があることを示唆しています。

16

Swift 3では、彼らはもはやプロトコル上のオプションとしてマークされていないため、D新しいプロトコル

session:activationDidCompleteWithState:error:

sessionDidBecomeInactive:

sessionDidDeactivate:

に応じて、このメソッドを実装します。

+0

ベストSwift 3/iOS10/XCode 8に関する最新の回答 – Josh

関連する問題