2014-11-18 5 views
0

내 클래스에 옵저버를 추가하여 권한 변경시 GameKit으로부터 알림을 받도록하려고합니다.iOS Swift 메시지가 할당 해제 된 인스턴스로 전송되었습니다. 알림이 있습니다.

2014-11-18 13:11:19.262 Name[8074:1078111] *** -[Name authenticationChanged:]: message sent to deallocated instance 0x174423500 

내가 잘못 뭐하는 거지 : 여기

는 관찰자와 방법이
override init(){ 
    super.init() 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: NSSelectorFromString("authenticationChanged:"), name: GKPlayerAuthenticationDidChangeNotificationName, object: nil) 
} 

func authenticationChanged(notification:NSNotification){ 

} 

를 호출해야하지만 내게이 오류를주고를 추가하는 코드는?

답변

3

개체의 할당이 해제되었습니다. 당신은 관찰자로서 자신을 옵서버로 취할 필요가 있습니다.

deinit { 
    NSNotificationCenter.defaultCenter().removeObserver(self) 
} 
+0

즉각적으로 작업했습니다. 예제 코드를 넣으려면 올바른 대답을 선택하십시오 – Jan

+0

이것은 작동 한 코드입니다. deinit {NSNotificationCenter.defaultCenter(). removeObserver (self)} 그냥 답에 추가하면 선택하게됩니다. 원래 팁 주셔서 감사합니다. – Jan