Should I fix Xcode 5 'Semantic issue: undeclared selector'?

后端 未结 4 808
醉梦人生
醉梦人生 2020-12-14 01:32

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 mi

相关标签:
4条回答
  • 2020-12-14 01:45

    Yes you should.

    instead of doing this:

    [self.searchResults sortUsingSelector:@selector(compareByDeliveryTime:)];
    

    you should do this:

    SEL compareByDeliveryTimeSelector = sel_registerName("compareByDeliveryTime:");
    [self.searchResults sortUsingSelector:compareByDeliveryTimeSelector];
    
    0 讨论(0)
  • 2020-12-14 01:56

    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

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wundeclared-selector"
    

    and at the end

    #pragma clang diagnostic pop
    
    0 讨论(0)
  • 2020-12-14 01:59

    You just need to declare a class or protocol that contains the selector. For example:

    //  DeliveryTimeComparison.h
    #import <Foundation/Foundation.h>
    
    @protocol DeliveryTimeComparison <NSObject>
    
    - (void)compareByDeliveryTime:(id)otherTime;
    
    @end
    

    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.

    0 讨论(0)
  • 2020-12-14 02:05

    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.

    0 讨论(0)
提交回复
热议问题