Under ARC, what’s the recommended/supported way to message an object, given the object reference and a selector? I’m implementing an instance of the target-action pattern that’s all over Cocoa, but running into roadblocks:
* If I try to use -[NSObject performSelector:withObject:] I get a compiler error “PerformSelector may cause a leak because its selector is unknown”. * If I try to call objc_msgSend directly, it doesn’t work because <objc/message.h> has purposely obfuscated the real signature of the function to hide its parameters. (Unless I redefine OBJC_OLD_DISPATCH_PROTOTYPES as 1, but even if I do that it doesn’t take effect; I’m suspecting message.h gets imported during my prefix header or something.) I’m aware that _in general_, dynamic dispatch can cause bad side effects under ARC. But all I want to do is send a message that takes an NSObject parameter and returns void, which is safe. Something like: Widget* newWidget = [self receiveWidget]; SEL action = [self lookupActionForWidget: newWidget]; [self.delegate performSelector: action withObject: newWidget]; —Jens PS: Using Xcode 6.3, latest SDKs, -Wall, -Werror, etc. _______________________________________________ Do not post admin requests to the list. They will be ignored. Objc-language mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com This email sent to [email protected]
