I’m using the following code to add a displayValue method to NSObject:
@interface NSObject (MyNSObjectAdditions)
- (NSString*)displayValue;
@end
@implementation NSObject (MyNSObjectAdditions)
- (NSString*)displayValue {
return self.description;
}
@end
This works great, but really I’d rather have displayValue be a read-only property instead of a method.
What would be the proper syntax to convert displayValue to be a property instead of a selector, if it’s even possible?
You can only add new methods to a class using categories. If you really want to add new instance variables, you will have to subclass NSObject.
In any case, adding functionalities to NSObject is rarely a good idea. Can you explain what you are trying to achieve?