Re: How can I get rid of this warning message?
Re: How can I get rid of this warning message?
- Subject: Re: How can I get rid of this warning message?
- From: Rick Aurbach <email@hidden>
- Date: Tue, 22 Jan 2013 14:38:51 -0500
- Acceptlanguage: en-US
- Thread-topic: How can I get rid of this warning message?
Thank you for the explanation. I only started learning Objective-C, Cocoa, iOS, etc in August, so I'm still pretty much a newbie and appreciate learning something new.
In this particular case, the selector that is the argument to the performSelector: method is a callback selector for NSTimer and hence is known to return void. Therefore, using the #pragma to turn off this message is safe.
Thanks for the insight.
Rick Aurbach
Aurbach & Associates, Inc.
On Jan 21, 2013, at 2:45 PM, Greg Parker <email@hidden> wrote:
> On Jan 21, 2013, at 12:20 PM, Rick Aurbach <email@hidden> wrote:
>> It appears to work great, but I find that the class's executeSelector: method generates a warning message.
>>
>>> - (void) executeSelector:(NSTimer*)timer {
>>> if(self.target != nil) {
>>> if([self.target respondsToSelector:self.sel])
>>> [self.target performSelector:self.sel withObject:self];
>>> }
>>> else
>>> [self invalidate];
>>> }
>>
>> where sel is defined as @property(nonatomic) SEL sel;
>>
>> The line containing the performSelector:withObject: method generates
>> "PerformSelector may cause a leak because its selector is unknown".
>>
>> Ok, I agree that the selector is unknown, but we know from the previous line that the target responds to it.
>
> That's not what it's complaining about. It's complaining because the ARC compiler cannot see the name of the method you are calling, so ARC doesn't know whether its return value needs to be released.
>
>
>> So I'd like to prevent this particular warning. I'm sure I ought to know how do do this, but how do I go about removing this warning message? Ideally, I'd like to do this on a file (or occurrence) basis, so that I can make sure that other similar usages are similarly safe.
>
> If you know the selectors you are calling do not return a retained object, you can use #pragma clang diagnostic to disable warning -Warc-performSelector-leaks around that line.
>
>
> --
> Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden