How to get rid of the 'undeclared selector' warning
I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there's a category method that should set an error property if the NSObject instance it's called on supports it. This is the code, and the code works as intended:
if ([self respondsToSelector:@selector(setError:)])
[self performSelector:@selector(setError:) withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
However, the compiler doesn't see any method around with the setError: signature, so it gives me a warning, for each line that contains the @selector(setError:)
snippet:
Undeclared selector 'setError:'
I don't want to have to declare a protocol to get rid of this warning, because I don't want all classes that may use this to implement anything special. Just by convention I want them to have a setError:
method or property.
Is this doable? How?
Cheers,
EP
objective-c selector categories
add a comment |
I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there's a category method that should set an error property if the NSObject instance it's called on supports it. This is the code, and the code works as intended:
if ([self respondsToSelector:@selector(setError:)])
[self performSelector:@selector(setError:) withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
However, the compiler doesn't see any method around with the setError: signature, so it gives me a warning, for each line that contains the @selector(setError:)
snippet:
Undeclared selector 'setError:'
I don't want to have to declare a protocol to get rid of this warning, because I don't want all classes that may use this to implement anything special. Just by convention I want them to have a setError:
method or property.
Is this doable? How?
Cheers,
EP
objective-c selector categories
2
The solution is well explained in performSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 12:01
add a comment |
I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there's a category method that should set an error property if the NSObject instance it's called on supports it. This is the code, and the code works as intended:
if ([self respondsToSelector:@selector(setError:)])
[self performSelector:@selector(setError:) withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
However, the compiler doesn't see any method around with the setError: signature, so it gives me a warning, for each line that contains the @selector(setError:)
snippet:
Undeclared selector 'setError:'
I don't want to have to declare a protocol to get rid of this warning, because I don't want all classes that may use this to implement anything special. Just by convention I want them to have a setError:
method or property.
Is this doable? How?
Cheers,
EP
objective-c selector categories
I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there's a category method that should set an error property if the NSObject instance it's called on supports it. This is the code, and the code works as intended:
if ([self respondsToSelector:@selector(setError:)])
[self performSelector:@selector(setError:) withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
However, the compiler doesn't see any method around with the setError: signature, so it gives me a warning, for each line that contains the @selector(setError:)
snippet:
Undeclared selector 'setError:'
I don't want to have to declare a protocol to get rid of this warning, because I don't want all classes that may use this to implement anything special. Just by convention I want them to have a setError:
method or property.
Is this doable? How?
Cheers,
EP
objective-c selector categories
objective-c selector categories
edited Aug 9 '16 at 14:07
epologee
asked Jun 3 '11 at 8:57
epologeeepologee
5,93595498
5,93595498
2
The solution is well explained in performSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 12:01
add a comment |
2
The solution is well explained in performSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 12:01
2
2
The solution is well explained in performSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 12:01
The solution is well explained in performSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 12:01
add a comment |
12 Answers
12
active
oldest
votes
Another option would be to disable the warning with:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
You can place this line in the .m file where the warning occurs.
Update:
It works also with LLVM like this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
... your code here ...
#pragma clang diagnostic pop
1
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
I alson needed#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
1
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
|
show 1 more comment
Have a look at NSSelectorFromString.
SEL selector = NSSelectorFromString(@"setError:");
if ([self respondsToSelector:selector])
It will allow you to create a selector at runtime, instead of at compile time through the @selector
keyword, and the compiler will have no chance to complain.
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
I like this answer more because it looks more "Cocoa"-y (?). Thesel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)
– Nicolas Miari
Sep 16 '13 at 15:18
14
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
1
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
add a comment |
I think this is because for some odd reason the selector isn't registered with the runtime.
Try registering the selector via sel_registerName()
:
SEL setErrorSelector = sel_registerName("setError:");
if([self respondsToSelector:setErrorSelector])
[self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
@epologeeNSSelectorFromString
callssel_registerName()
under the hood anyway. Choose whichever suits you better.
– Jacob Relkin
Jun 3 '11 at 9:24
1
@epologee I think that callingsel_registerName()
directly is more explicit about why you're doing it.NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.
– Jacob Relkin
Jun 3 '11 at 9:26
8
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
add a comment |
I got that message to go away by #include'ing the file with the method. Nothing else was used from that file.
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
2
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
add a comment |
I realise I'm a bit late to this thread but for completeness, you can globally turn off this warning using the target build settings.
In section, 'Apple LLVM warnings - Objective-C', change:
Undeclared Selector - NO
add a comment |
If your class implements the setError: method (even by declaring dynamic the setter of the eventual error property) you might want to declare it in your interface file ( .h), or if you don't like to show it that way you could try with the PrivateMethods tricky trick:
@interface Yourclass (PrivateMethods)
- (void) yourMethod1;
- (void) yourMethod2;
@end
just before your @implementation , this should hide the warnings ;).
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
1
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can seePerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
add a comment |
A really comfortable macro to put in your .pch
or Common.h
or wherever you want:
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code)
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored "-Wundeclared-selector""")
code;
_Pragma("clang diagnostic pop")
It's an edit of this question for similar issue...
add a comment |
You can turn it off in Xcode like in the screenshot:
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
add a comment |
You can also cast the object in question to an id first to avoid the warning:
if ([object respondsToSelector:@selector(myMethod)])
[(id)object myMethod];
1
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
add a comment |
Another way to avoid this warning is to make sure your selector method looks like this:
-(void) myMethod :(id) sender
Don't forget "(id) sender" if you want to accept any sender or specify a type of a sender object if you prefer.
add a comment |
While the correct answer likely lies in informing Xcode through imports or registering the selector that such a selector exists, in my case I was missing a semi-colon. Make sure before you "fix" the error that perhaps, the error is correct and your code isn't. I found the error in Apple's MVCNetworking sample, for instance.
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
1
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
add a comment |
I was able to get the warning to go away by adding thenothing method (disclosure: I didn't think of this but found it by googling on scheduledtimerwithtimeinterval)
[NSTimer scheduledTimerWithTimeInterval:[[NSDate distantFuture] timeIntervalSinceNow]
target:self
selector:@selector(donothingatall:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] run];
HTTPLogVerbose(@"%@: BonjourThread: Aborted", THIS_FILE);
}
}
+ (void) donothingatall:(NSTimer *)timer
While I appreciate knowing how to hide the warning, fixing it is better and neither Sergio's nor Relkin's techniques worked for me, for unknown reasons.
1
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
1
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6224976%2fhow-to-get-rid-of-the-undeclared-selector-warning%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
12 Answers
12
active
oldest
votes
12 Answers
12
active
oldest
votes
active
oldest
votes
active
oldest
votes
Another option would be to disable the warning with:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
You can place this line in the .m file where the warning occurs.
Update:
It works also with LLVM like this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
... your code here ...
#pragma clang diagnostic pop
1
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
I alson needed#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
1
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
|
show 1 more comment
Another option would be to disable the warning with:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
You can place this line in the .m file where the warning occurs.
Update:
It works also with LLVM like this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
... your code here ...
#pragma clang diagnostic pop
1
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
I alson needed#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
1
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
|
show 1 more comment
Another option would be to disable the warning with:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
You can place this line in the .m file where the warning occurs.
Update:
It works also with LLVM like this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
... your code here ...
#pragma clang diagnostic pop
Another option would be to disable the warning with:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
You can place this line in the .m file where the warning occurs.
Update:
It works also with LLVM like this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
... your code here ...
#pragma clang diagnostic pop
edited Aug 21 '13 at 14:29
answered May 8 '12 at 23:50
KlaasKlaas
17.5k107590
17.5k107590
1
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
I alson needed#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
1
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
|
show 1 more comment
1
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
I alson needed#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
1
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
1
1
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
does this work for LLVM as well?
– epologee
May 9 '12 at 12:42
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Do your thing
#pragma clang diagnostic pop
– dizy
Aug 21 '13 at 3:50
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
yes, It does as @dizy states. (Sorry for the late answer, but I missed the notification).
– Klaas
Aug 21 '13 at 14:28
I alson needed
#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
I alson needed
#pragma clang diagnostic ignored "-Wselector"
– max
Sep 22 '13 at 15:14
1
1
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
@mdorseif Most of the time the warning that you 'have to' exclude is listed in the compile log. You can mute any warning with this concept. Glad you added yours regarding selectors.
– Klaas
Sep 22 '13 at 19:16
|
show 1 more comment
Have a look at NSSelectorFromString.
SEL selector = NSSelectorFromString(@"setError:");
if ([self respondsToSelector:selector])
It will allow you to create a selector at runtime, instead of at compile time through the @selector
keyword, and the compiler will have no chance to complain.
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
I like this answer more because it looks more "Cocoa"-y (?). Thesel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)
– Nicolas Miari
Sep 16 '13 at 15:18
14
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
1
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
add a comment |
Have a look at NSSelectorFromString.
SEL selector = NSSelectorFromString(@"setError:");
if ([self respondsToSelector:selector])
It will allow you to create a selector at runtime, instead of at compile time through the @selector
keyword, and the compiler will have no chance to complain.
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
I like this answer more because it looks more "Cocoa"-y (?). Thesel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)
– Nicolas Miari
Sep 16 '13 at 15:18
14
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
1
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
add a comment |
Have a look at NSSelectorFromString.
SEL selector = NSSelectorFromString(@"setError:");
if ([self respondsToSelector:selector])
It will allow you to create a selector at runtime, instead of at compile time through the @selector
keyword, and the compiler will have no chance to complain.
Have a look at NSSelectorFromString.
SEL selector = NSSelectorFromString(@"setError:");
if ([self respondsToSelector:selector])
It will allow you to create a selector at runtime, instead of at compile time through the @selector
keyword, and the compiler will have no chance to complain.
edited Jun 3 '11 at 9:08
answered Jun 3 '11 at 9:02
sergiosergio
66.4k990116
66.4k990116
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
I like this answer more because it looks more "Cocoa"-y (?). Thesel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)
– Nicolas Miari
Sep 16 '13 at 15:18
14
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
1
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
add a comment |
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
I like this answer more because it looks more "Cocoa"-y (?). Thesel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)
– Nicolas Miari
Sep 16 '13 at 15:18
14
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
1
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
Hi @sergio, both your and @jacobrelkin's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
2
I like this answer more because it looks more "Cocoa"-y (?). The
sel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)– Nicolas Miari
Sep 16 '13 at 15:18
I like this answer more because it looks more "Cocoa"-y (?). The
sel_registerName()
thingy looks obscure and the kind you shouldn't be calling directly unless you know what you're doing, kinda like obj_msg_send() ;)– Nicolas Miari
Sep 16 '13 at 15:18
14
14
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:38
1
1
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
@Hampden123: that is a different issue. have a look here: stackoverflow.com/questions/7017281/…
– sergio
Nov 20 '13 at 17:50
add a comment |
I think this is because for some odd reason the selector isn't registered with the runtime.
Try registering the selector via sel_registerName()
:
SEL setErrorSelector = sel_registerName("setError:");
if([self respondsToSelector:setErrorSelector])
[self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
@epologeeNSSelectorFromString
callssel_registerName()
under the hood anyway. Choose whichever suits you better.
– Jacob Relkin
Jun 3 '11 at 9:24
1
@epologee I think that callingsel_registerName()
directly is more explicit about why you're doing it.NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.
– Jacob Relkin
Jun 3 '11 at 9:26
8
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
add a comment |
I think this is because for some odd reason the selector isn't registered with the runtime.
Try registering the selector via sel_registerName()
:
SEL setErrorSelector = sel_registerName("setError:");
if([self respondsToSelector:setErrorSelector])
[self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
@epologeeNSSelectorFromString
callssel_registerName()
under the hood anyway. Choose whichever suits you better.
– Jacob Relkin
Jun 3 '11 at 9:24
1
@epologee I think that callingsel_registerName()
directly is more explicit about why you're doing it.NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.
– Jacob Relkin
Jun 3 '11 at 9:26
8
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
add a comment |
I think this is because for some odd reason the selector isn't registered with the runtime.
Try registering the selector via sel_registerName()
:
SEL setErrorSelector = sel_registerName("setError:");
if([self respondsToSelector:setErrorSelector])
[self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
I think this is because for some odd reason the selector isn't registered with the runtime.
Try registering the selector via sel_registerName()
:
SEL setErrorSelector = sel_registerName("setError:");
if([self respondsToSelector:setErrorSelector])
[self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
answered Jun 3 '11 at 9:03
Jacob RelkinJacob Relkin
136k24316303
136k24316303
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
@epologeeNSSelectorFromString
callssel_registerName()
under the hood anyway. Choose whichever suits you better.
– Jacob Relkin
Jun 3 '11 at 9:24
1
@epologee I think that callingsel_registerName()
directly is more explicit about why you're doing it.NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.
– Jacob Relkin
Jun 3 '11 at 9:26
8
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
add a comment |
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
@epologeeNSSelectorFromString
callssel_registerName()
under the hood anyway. Choose whichever suits you better.
– Jacob Relkin
Jun 3 '11 at 9:24
1
@epologee I think that callingsel_registerName()
directly is more explicit about why you're doing it.NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.
– Jacob Relkin
Jun 3 '11 at 9:26
8
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
Hi @jacobrelkin, both your and @sergio's answers work. Pretty much submitted simultaneously. Will you help me pick the 'better' answer, if there is one?
– epologee
Jun 3 '11 at 9:18
2
2
@epologee
NSSelectorFromString
calls sel_registerName()
under the hood anyway. Choose whichever suits you better.– Jacob Relkin
Jun 3 '11 at 9:24
@epologee
NSSelectorFromString
calls sel_registerName()
under the hood anyway. Choose whichever suits you better.– Jacob Relkin
Jun 3 '11 at 9:24
1
1
@epologee I think that calling
sel_registerName()
directly is more explicit about why you're doing it. NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.– Jacob Relkin
Jun 3 '11 at 9:26
@epologee I think that calling
sel_registerName()
directly is more explicit about why you're doing it. NSSelectorFromString
doesn't tell you that it's going to attempt to register the selector.– Jacob Relkin
Jun 3 '11 at 9:26
8
8
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
Not sure if it's Xcode 5, but I'm getting a different warning with this implementation: "PerformSelector may cause a leak because its selector is unknown".
– Hampden123
Nov 20 '13 at 16:36
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
@Max_Power89 No. See my other comments below. I didn't want to spend too much time on this so I simply included the header files.
– Hampden123
Nov 26 '13 at 16:53
add a comment |
I got that message to go away by #include'ing the file with the method. Nothing else was used from that file.
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
2
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
add a comment |
I got that message to go away by #include'ing the file with the method. Nothing else was used from that file.
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
2
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
add a comment |
I got that message to go away by #include'ing the file with the method. Nothing else was used from that file.
I got that message to go away by #include'ing the file with the method. Nothing else was used from that file.
answered Nov 5 '13 at 4:31
Mark PattersonMark Patterson
191314
191314
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
2
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
add a comment |
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
2
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
While this is less graceful solution, it works for me as I have the "known suspects" who might be receiving the selector. Also, if I implement the runtime selector approach, I'd still get a different warning at the performSelector statement; namely, "PerformSelector may cause a leak because its selector is unknown". So thanks!
– Hampden123
Nov 20 '13 at 16:31
2
2
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
Neither of the top voted answers is correct. The intent of the "undeclared selector" warning is to catch errors at compile time if you change the name of the selector you were relying on. So it is most correct to #import the file that declares the method you were relying on.
– Brane
Feb 18 '14 at 16:04
add a comment |
I realise I'm a bit late to this thread but for completeness, you can globally turn off this warning using the target build settings.
In section, 'Apple LLVM warnings - Objective-C', change:
Undeclared Selector - NO
add a comment |
I realise I'm a bit late to this thread but for completeness, you can globally turn off this warning using the target build settings.
In section, 'Apple LLVM warnings - Objective-C', change:
Undeclared Selector - NO
add a comment |
I realise I'm a bit late to this thread but for completeness, you can globally turn off this warning using the target build settings.
In section, 'Apple LLVM warnings - Objective-C', change:
Undeclared Selector - NO
I realise I'm a bit late to this thread but for completeness, you can globally turn off this warning using the target build settings.
In section, 'Apple LLVM warnings - Objective-C', change:
Undeclared Selector - NO
answered Apr 30 '15 at 9:45
QuixioteQuixiote
7617
7617
add a comment |
add a comment |
If your class implements the setError: method (even by declaring dynamic the setter of the eventual error property) you might want to declare it in your interface file ( .h), or if you don't like to show it that way you could try with the PrivateMethods tricky trick:
@interface Yourclass (PrivateMethods)
- (void) yourMethod1;
- (void) yourMethod2;
@end
just before your @implementation , this should hide the warnings ;).
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
1
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can seePerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
add a comment |
If your class implements the setError: method (even by declaring dynamic the setter of the eventual error property) you might want to declare it in your interface file ( .h), or if you don't like to show it that way you could try with the PrivateMethods tricky trick:
@interface Yourclass (PrivateMethods)
- (void) yourMethod1;
- (void) yourMethod2;
@end
just before your @implementation , this should hide the warnings ;).
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
1
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can seePerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
add a comment |
If your class implements the setError: method (even by declaring dynamic the setter of the eventual error property) you might want to declare it in your interface file ( .h), or if you don't like to show it that way you could try with the PrivateMethods tricky trick:
@interface Yourclass (PrivateMethods)
- (void) yourMethod1;
- (void) yourMethod2;
@end
just before your @implementation , this should hide the warnings ;).
If your class implements the setError: method (even by declaring dynamic the setter of the eventual error property) you might want to declare it in your interface file ( .h), or if you don't like to show it that way you could try with the PrivateMethods tricky trick:
@interface Yourclass (PrivateMethods)
- (void) yourMethod1;
- (void) yourMethod2;
@end
just before your @implementation , this should hide the warnings ;).
answered Jun 3 '11 at 9:25
i_mushi_mush
146110
146110
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
1
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can seePerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
add a comment |
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
1
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can seePerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
Thanks, but I'm calling the method from a category, so this does not apply. Cheers, EP.
– epologee
Jun 3 '11 at 10:06
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
And some of us are doing things that are more exotic - the selector is implemented in an F# object, in my case.
– James Moore
Oct 21 '13 at 23:00
1
1
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can see
PerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
This does not get rid of the warning in XCode 7.1.1 / iOS 9.1, I can see
PerformSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 11:46
add a comment |
A really comfortable macro to put in your .pch
or Common.h
or wherever you want:
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code)
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored "-Wundeclared-selector""")
code;
_Pragma("clang diagnostic pop")
It's an edit of this question for similar issue...
add a comment |
A really comfortable macro to put in your .pch
or Common.h
or wherever you want:
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code)
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored "-Wundeclared-selector""")
code;
_Pragma("clang diagnostic pop")
It's an edit of this question for similar issue...
add a comment |
A really comfortable macro to put in your .pch
or Common.h
or wherever you want:
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code)
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored "-Wundeclared-selector""")
code;
_Pragma("clang diagnostic pop")
It's an edit of this question for similar issue...
A really comfortable macro to put in your .pch
or Common.h
or wherever you want:
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code)
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored "-Wundeclared-selector""")
code;
_Pragma("clang diagnostic pop")
It's an edit of this question for similar issue...
edited May 23 '17 at 12:26
Community♦
11
11
answered Apr 13 '14 at 13:09
Aviel GrossAviel Gross
7,4503954
7,4503954
add a comment |
add a comment |
You can turn it off in Xcode like in the screenshot:
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
add a comment |
You can turn it off in Xcode like in the screenshot:
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
add a comment |
You can turn it off in Xcode like in the screenshot:
You can turn it off in Xcode like in the screenshot:
answered Oct 11 '16 at 4:11
SmallChessSmallChess
5,02273866
5,02273866
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
add a comment |
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
Nice one. Still, I prefer disabling the warning only for explicit cases, by means of saying "clang is wrong in this occasion, I know what I'm doing". Thanks for your input!
– epologee
Oct 12 '16 at 21:38
add a comment |
You can also cast the object in question to an id first to avoid the warning:
if ([object respondsToSelector:@selector(myMethod)])
[(id)object myMethod];
1
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
add a comment |
You can also cast the object in question to an id first to avoid the warning:
if ([object respondsToSelector:@selector(myMethod)])
[(id)object myMethod];
1
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
add a comment |
You can also cast the object in question to an id first to avoid the warning:
if ([object respondsToSelector:@selector(myMethod)])
[(id)object myMethod];
You can also cast the object in question to an id first to avoid the warning:
if ([object respondsToSelector:@selector(myMethod)])
[(id)object myMethod];
answered Aug 5 '14 at 7:46
SwindlerSwindler
63277
63277
1
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
add a comment |
1
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
1
1
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
This doesn't get rid of the same warning on the if expression content, all the way up to XC7.1 to this day.
– Martin-Gilles Lavoie
Oct 26 '15 at 20:11
add a comment |
Another way to avoid this warning is to make sure your selector method looks like this:
-(void) myMethod :(id) sender
Don't forget "(id) sender" if you want to accept any sender or specify a type of a sender object if you prefer.
add a comment |
Another way to avoid this warning is to make sure your selector method looks like this:
-(void) myMethod :(id) sender
Don't forget "(id) sender" if you want to accept any sender or specify a type of a sender object if you prefer.
add a comment |
Another way to avoid this warning is to make sure your selector method looks like this:
-(void) myMethod :(id) sender
Don't forget "(id) sender" if you want to accept any sender or specify a type of a sender object if you prefer.
Another way to avoid this warning is to make sure your selector method looks like this:
-(void) myMethod :(id) sender
Don't forget "(id) sender" if you want to accept any sender or specify a type of a sender object if you prefer.
answered Nov 14 '18 at 14:58
ReposeRepose
1,14711018
1,14711018
add a comment |
add a comment |
While the correct answer likely lies in informing Xcode through imports or registering the selector that such a selector exists, in my case I was missing a semi-colon. Make sure before you "fix" the error that perhaps, the error is correct and your code isn't. I found the error in Apple's MVCNetworking sample, for instance.
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
1
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
add a comment |
While the correct answer likely lies in informing Xcode through imports or registering the selector that such a selector exists, in my case I was missing a semi-colon. Make sure before you "fix" the error that perhaps, the error is correct and your code isn't. I found the error in Apple's MVCNetworking sample, for instance.
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
1
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
add a comment |
While the correct answer likely lies in informing Xcode through imports or registering the selector that such a selector exists, in my case I was missing a semi-colon. Make sure before you "fix" the error that perhaps, the error is correct and your code isn't. I found the error in Apple's MVCNetworking sample, for instance.
While the correct answer likely lies in informing Xcode through imports or registering the selector that such a selector exists, in my case I was missing a semi-colon. Make sure before you "fix" the error that perhaps, the error is correct and your code isn't. I found the error in Apple's MVCNetworking sample, for instance.
answered Oct 22 '13 at 18:20
Louis St-AmourLouis St-Amour
3,34912324
3,34912324
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
1
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
add a comment |
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
1
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
No, the correct answer was not in informing Xcode through imports, because those imports were in place. The correct answer was the answer above that was marked as ... the correct answer, although @sergio's answer would also solve the issue. Using the wrong selector is not the subject of this question, therefore changing the selector is not an answer. I'll save you the downvote though.
– epologee
Oct 23 '13 at 11:29
1
1
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
Thanks for reminding me that I probably should have used a comment. All I can say is that missing imports also cause this Xcode warning, if not this specific instance. I would only recommend NSSelectorFromString or other such "registration" options when building a selector at runtime or responding to method calls in a dynamic fashion (e.g. methodSignatureForSelector). Registering it means you're "working around the error" and so isn't correct for some circumstances, because a more correct approach would be to fix the warning (if the clang analysis was correct, that is.)
– Louis St-Amour
Oct 28 '13 at 19:47
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
In fact, I now see that the original question clearly says, "without the need for an implemented protocol" -- and does not mention imports at all. So I would put forth that importing the category itself might be the best option for this user. Anything else here could define the selector twice, technically speaking. Yes? -- Edit: Ah, I've taken this too far. Thanks for your response, I'll stop now. :)
– Louis St-Amour
Oct 28 '13 at 19:50
add a comment |
I was able to get the warning to go away by adding thenothing method (disclosure: I didn't think of this but found it by googling on scheduledtimerwithtimeinterval)
[NSTimer scheduledTimerWithTimeInterval:[[NSDate distantFuture] timeIntervalSinceNow]
target:self
selector:@selector(donothingatall:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] run];
HTTPLogVerbose(@"%@: BonjourThread: Aborted", THIS_FILE);
}
}
+ (void) donothingatall:(NSTimer *)timer
While I appreciate knowing how to hide the warning, fixing it is better and neither Sergio's nor Relkin's techniques worked for me, for unknown reasons.
1
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
1
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
add a comment |
I was able to get the warning to go away by adding thenothing method (disclosure: I didn't think of this but found it by googling on scheduledtimerwithtimeinterval)
[NSTimer scheduledTimerWithTimeInterval:[[NSDate distantFuture] timeIntervalSinceNow]
target:self
selector:@selector(donothingatall:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] run];
HTTPLogVerbose(@"%@: BonjourThread: Aborted", THIS_FILE);
}
}
+ (void) donothingatall:(NSTimer *)timer
While I appreciate knowing how to hide the warning, fixing it is better and neither Sergio's nor Relkin's techniques worked for me, for unknown reasons.
1
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
1
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
add a comment |
I was able to get the warning to go away by adding thenothing method (disclosure: I didn't think of this but found it by googling on scheduledtimerwithtimeinterval)
[NSTimer scheduledTimerWithTimeInterval:[[NSDate distantFuture] timeIntervalSinceNow]
target:self
selector:@selector(donothingatall:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] run];
HTTPLogVerbose(@"%@: BonjourThread: Aborted", THIS_FILE);
}
}
+ (void) donothingatall:(NSTimer *)timer
While I appreciate knowing how to hide the warning, fixing it is better and neither Sergio's nor Relkin's techniques worked for me, for unknown reasons.
I was able to get the warning to go away by adding thenothing method (disclosure: I didn't think of this but found it by googling on scheduledtimerwithtimeinterval)
[NSTimer scheduledTimerWithTimeInterval:[[NSDate distantFuture] timeIntervalSinceNow]
target:self
selector:@selector(donothingatall:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] run];
HTTPLogVerbose(@"%@: BonjourThread: Aborted", THIS_FILE);
}
}
+ (void) donothingatall:(NSTimer *)timer
While I appreciate knowing how to hide the warning, fixing it is better and neither Sergio's nor Relkin's techniques worked for me, for unknown reasons.
answered Nov 28 '14 at 21:41
user938797user938797
60212
60212
1
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
1
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
add a comment |
1
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
1
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
1
1
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
If someone else reads this solution, which will work, he/she will be pretty confused, including your future self. If you're sure you know what you're doing by calling a non-existing selector, thereby causing a warning, skip the misleading method stub and ensure your code expresses your intent.
– epologee
Dec 7 '14 at 12:01
1
1
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
Good point. I was working with inherited code and just trying to figure out how to make the warning go away, not trying to solve the basic question of why have a non-existent selector. One step at a time, I always say.
– user938797
Dec 8 '14 at 18:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6224976%2fhow-to-get-rid-of-the-undeclared-selector-warning%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The solution is well explained in performSelector may cause a leak because its selector is unknown
– loretoparisi
Nov 18 '15 at 12:01