2016-06-18 2 views
3

엑스 코드 8 (베타 1)와 스위프트 3 업그레이드 이후이 줄에 오류가 있습니다유형 '의 UIViewController'프로토콜을 준수하지 않는 'WCSessionDelegate'

class CloudViewController: UIViewController, WCSessionDelegate { 

은 말한다 :

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

이 내 (엑스 코드 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에, 당신은 지금처럼 UITableViewDataSource, UITableViewDelegate 프로토콜을 추가해야합니다. 이것은 단순한 선언입니다.

실제로보기 컨트롤러가 프로토콜을 준수하게하려면 두 가지 방법, 즉 cellForRowAtIndexPathnumberOfRowsInSection을 구현해야합니다. 이것은 프로토콜의 요구 사항입니다.

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 
    } 

} 

따라서, 당신은 문서로보고 방법이 프로토콜을 구현하는 클래스를 필요로 무엇을 발견해야한다 :

그래서 완전한 구현은 같을 것입니다. 그러면이 문제가 해결됩니다. 그리고 나는 그것이 엑스 코드 8 빠른 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

스위프트 3에서는 shoul 그들은 더 이상 프로토콜에 옵션으로 표시되지 않기 때문에 새로운 프로토콜

session:activationDidCompleteWithState:error:

sessionDidBecomeInactive:

sessionDidDeactivate:

에 따라이 방법을 구현하는 거라고.

+0

최고 Swift 3/iOS10/XCode 8에 대한 답변이 업데이트되었습니다. – Josh

관련 문제