I'm trying to upgrade my app with Xcode5 but encountered a number of 'Semantic issues' in a third party library (being MagicalRecord). The quickest way to 'fix' this might be using the:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
(from: How to get rid of the 'undeclared selector' warning)
compiler directive, but my gut-feeling says this is not the appropriate way to do this. A small code sample with the above error:
+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context {
if ([self respondsToSelector:@selector(entityInManagedObjectContext:)])
{
NSEntityDescription *entity = [self performSelector:@selector(entityInManagedObjectContext:) withObject:context];
return entity;
}
else
{
NSString *entityName = [self MR_entityName];
return [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
}
}
where the entityInManagedObjectContext:
method is not defined anywhere.
Any suggestions on how to best fix these types of errors, thanks in advance?!
Yes you should.
instead of doing this:
you should do this:
You just need to declare a class or protocol that contains the selector. For example:
And then simply
#import "DeliveryTimeComparison.h"
in any class where you plan to use@selector(compareByDeliveryTime:)
.Or alternatively, just import the class header for any object that contains a "compareByDeliveryTime:" method.
Xcode 5 turned this on by default. To turn it off go to "Build Settings" for your target under "Apple LLVM 5.0 - Warnings - Objective C" -> "Undeclared Selector" set it to "NO". This should take care of it.
These selector warnings in MagicalRecord are for compatibility with mogenerator's generated Core Data classes. Besides using mogenerator and perhaps importing one of the entities there really isn't much you can do besides what was already answered.
Another option of course is to surround that code specifically with ignore blocks
and at the end