1
votes

I was learning objective-c and found that I could call some methods of NSObject, but can't find them in the documentation. Such as the method valueForKey

NSObject *obj = [[NSObject alloc]init];
NSLog(@"%@", [obj valueForKey:@"class"]);

will print the class name. However NSObject seems not have method valueForKey https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html

Actually the protocal NSKeyValueCoding has that method but it seems the NSObject conforms only to NSObject protocal. https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/index.html

Could anyone explain?

2

2 Answers

2
votes

NSObject has a category that adds these methods:

@interface NSObject(NSKeyValueCoding)

Open xcode, press cmd + shft + o -- search for NSKeyValueCoding.h -- open it and see .

0
votes

NSKeyValueCoding appears to be an informal protocol, implemented by means of a category on NSObject and as such will not be part of the reference page of NSObject.