On Apr 29, 2014, at 3:30 PM, Greg Parker <[email protected]> wrote:
> On Apr 29, 2014, at 11:38 AM, Charles Srstka <[email protected]> wrote:
>> So it seems that even if the method is defined in a header, you need it to
>> be in the @implementation block of a class for which you have the code in
>> order to use @selector without setting off -Wselector. This means that
>> @selector cannot be used for methods in framework classes.
>
> Which compiler version is that? I think the compiler's diagnostics have been
> improved here.
It's the compiler that ships with Xcode 5.1.1 (5B1008).
>> You will need to either use NSSelectorFromString, find a way to use a
>> blocks-based approach (if it's possible), or just turn off -Wselector.
>
> One of the selector warnings (-Wundeclared-selector, in my compiler) is not
> part of -Wall precisely because it can be prone to false positives. If you
> don't like it, turn it off.
It's not -Wundeclared-selector that causes it, it's -Wselector:
#import <Foundation/Foundation.h>
// the warning doesn't occur unless there's an @implementation in the current
source file
@interface Foo : NSObject
@end
@implementation Foo
@end
int main (__unused int argc, __unused const char **argv) {
@autoreleasepool {
NSArray *array = [NSArray new];
[array sortedArrayUsingSelector:@selector(compare:)];
}
return 0;
}
$ clang -Wselector -framework Foundation test.m
test.m:13:41: warning: creating selector for nonexistent method 'compare:'
[-Wselector]
[array sortedArrayUsingSelector:@selector(compare:)];
^
1 warning generated.
$
However, with -Wundeclared-selector instead:
$ clang -Wundeclared-selector -framework Foundation test.m
$
Charles
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]