开发者

Cannot find protocol declaration for 'NSKeyValueObserving'. But,why?

@interface ThreadsViewController : UIViewController <NSKeyValueObserving>
{
}   

Error:Cannot find protocol declaration fo开发者_StackOverflow社区r 'NSKeyValueObserving'.

I'm using Foundation framework. Why do I have this error?


NSKeyValueObserving is an 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.

You can not adopt an informal protocol using the angle brackets syntax, that is for formal protocols. With informal protocols, you simply implement the protocol methods. Your attempt to conform to the protocol NSKeyValueObserving in the @interface block:

@interface ThreadsViewController : UIViewController <NSKeyValueObserving>

is the reason why the compiler is complaining.

From Protocols:

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.


You should check the documentation for NSKeyValueObserving. In that you can find at top that in which framework resides. Just confirm that you are including that framework in your project.


Are you sure FoundationFramework is added to your project? If not, add it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜