I created a class that has a specified objecttarget, a selectorto view, and displayTitledisplays a string in this format: @"displayTitle: object.selector". Then it registers through KVO, so that at any time valueof of it object.selectorchanges, it can notify the view controller to update the view. I use this as an abstract and reusable way to show a description of the various properties of an object to the user.
When I try to get the value object.selector, I cannot do [object performSelector:selector]it because LLVM gives errors when you use performSelector with a dynamic selector . So, I did exactly what this answer suggested: I used objc_msgSend(object, selector).
- (instancetype)initWithSelector:(SEL)selector onObject:(NSObject*)object displayTitle:(NSString*)displayTitle {
self = [super init];
if (self) {
id value;
if ([object respondsToSelector:selector) {
value = objc_msgSend(object, selector);
} else {
return nil;
}
[self setItemDescription:[NSString stringWithFormat:@"%@: %@", displayTitle, value]];
}
return self;
}
And I got it EXC_BAD_ACCESS!

, ,
[object selector].
, ?