Do static objective-c classes have to subclass NSObject?
In my objective-c project, I have a weird, lets say, feature I have a class, like this:
#import <Foundation/Foundation.h>
@interface Convert /* : NSObject */ // <--- is that necessary?
+(int) toInt:(id) obj;
@end
@implementation Convert
+(int) toInt:(id) obj
{
return [obj in开发者_Python百科tValue];
}
@end
What happens is, when I step through the code It works fine, but I get a cryptic error in the console (even though code is completely fine, works as expected):
2010-11-03 09:35:49.422 Tests[14066:5f03] *** NSInvocation: warning: object 0x9e424 of class 'Convert' does not implement methodSignatureForSelector: -- trouble ahead
2010-11-03 09:35:49.422 Tests[14066:5f03] *** NSInvocation: warning: object 0x9e424 of class 'Convert' does not implement doesNotRecognizeSelector: -- abort
Yet, even when It says abort, the code still works. However, when I run it without stepping through those lines of code, it aborts. What Is happening and why?
The simple answer is "yes".
Or more specifically, the runtime expects objects to conform to the NSObject
protocol, and the simplest way to do this is by making sure your objects inherit from the NSObject
class.
精彩评论