Suppose you have a class "Foo" with the property "testProperty". The goal is to get the name of the property (not the value) as NSString. Perhaps this question is duplicated. Get the property name as a string . But the answers did not help me, because:
- I do not need all the properties. I only need one.
- For
NSStringFromSelector(@selector(prop))- in any case, you need to enter a string.
Suppose I have a function like
- (NSString *)propertyToString:(id)propertyOfObject
In this case, I can use, for example, to sort
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[self propertyToString:foo.testProperty] ascending:NO];
So finally, the code will be clean.
source
share