Suppose you have a class "Foo" with property "testProperty". The aim is to get property name (not value) as NSString
. The question is probably duplicate of Get property name as a string . But that answers did not help me because:
- I don't need all properties. I need only particular one.
- For
NSStringFromSelector(@selector(prop))
- anyway you have to input string.
Suppose I have a function like
- (NSString *)propertyToString:(id)propertyOfObject
In that case I can use, for instance, for sorting
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[self propertyToString:foo.testProperty] ascending:NO];
So finally, the code will be clean.