@interface ThreadsViewController : UIViewController <NSKeyValueObserving>
{
}
錯誤:找不到'NSKeyValueObserving'的協議聲明。找不到'NSKeyValueObserving'的協議聲明。但爲什麼?
我在使用Foundation框架。爲什麼我有這個錯誤?
@interface ThreadsViewController : UIViewController <NSKeyValueObserving>
{
}
錯誤:找不到'NSKeyValueObserving'的協議聲明。找不到'NSKeyValueObserving'的協議聲明。但爲什麼?
我在使用Foundation框架。爲什麼我有這個錯誤?
NSKeyValueObserving
是informal protocol:
An informal protocol is a category on NSObject, which implicitly makes almost all objects adopters of the protocol. (...) Implementation of the methods in an informal protocol is optional. Before invoking a method, the calling object checks to see whether the target object implements it.
使用尖括號語法,你不能採取非正式的協議,這是正式的協議。使用非正式協議,您只需實現協議方法。你試圖順應協議NSKeyValueObserving
在@interface
塊:
@interface ThreadsViewController : UIViewController <NSKeyValueObserving>
是爲什麼編譯器是抱怨的原因。
Being informal, protocols declared in categories don’t receive much language support. There’s no type checking at compile time nor a check at runtime to see whether an object conforms to the protocol.
您應該檢查NSKeyValueObserving的文檔。在這裏你可以在頂部找到框架所在的位置。只需確認您在項目中包含該框架即可。
您確定FoundationFramework已添加到您的項目?如果沒有,請添加它。