I have a pointer in an objective-C class that I need to send messages to. The pointer can potentially be anything, so I need to make sure that it will respond to my messages before I send them. Here's the function I'm using to do the checking:
int delegatePreparedForSelector(id delegate, SEL aSelector) {
if (delegate
&& [delegate isKindOfClass:[NSObject class]]
&& [delegate respondsToSelector:aSelector]) {
return YES;
}
return NO;
}
The problem is that sometimes the delegate pointer is a struct objc-object *
and I get a EXC_BAD_ACCESS
bad access error when i send the isKindOfClass
message.
Is there a better test i should be using to determine if the delegate will respond to my messages?