New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tack on a (nil) argument if the selector is asking for one #1724
Conversation
With this change, I just get a crash in In any case, if the problem is that not enough arguments are being passed to the selector, why does it get through |
Hmm... I see your point Rob. I think this gives the answer. When |
From what I gather we have two ways we can go:
Personally I think we should go with option 1, but am open to discussion |
You can use, in ARC, without error:
|
True, that doesn't crash, but this does: @interface ISAppDelegate (extras)
@property id thing;
@end
@implementation ISAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// this crashes
[self performSelector:@selector(test:)];
}
- (void)test:(id)sender {
// retain 'thing'
self.thing = sender;
// release 'thing' (and 'sender' - which is GARBAGE!)
self.thing = nil;
}
@end Basically, trying to do something with the object (i.e. retain/release it) causes a crash. As for the 2nd crash - it is because in our current code we're trying to get a 'return value' from @implementation ISAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// this crashes
id result = [self performSelector:@selector(test:) withObject:nil];
}
- (IBAction)test:(id)sender {
// retain 'thing'
self.thing = sender;
// release 'thing' (and sender. In this case it's fine, because we've explicitly sent `nil` above)
self.thing = nil;
// nothing is returned... we're void
} |
The use of result was never actually implemented anyway, and was causing a crash
Tack on a (nil) argument if the selector is asking for one
Seems like pre-ARC would tack on a
nil
argument when callingperformSelector:
on a selector that required an argument, but for which none was provided.Now, we have to explicitly check if the selector requires an argument, and tack one on (
nil
in this case) if none is provided.Fixes @philostein's bug found Rob mentioned