@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已添加到您的项目?如果没有,请添加它。