本文介绍了我应该修复Xcode 5'语义问题:未声明的选择器'吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xcode5升级我的应用,但在第三方库(MagicalRecord)中遇到了许多语义问题。
修复这个最快的方法可能是使用:

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"

(来自:)

编译器指令,但我的直觉说这不是这样做的合适方式。
带有上述错误的小代码示例:

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];
    }
}

其中 entityInManagedObjectContext:方法未在任何地方定义。

where the entityInManagedObjectContext: method is not defined anywhere.

有关如何最好地修复这些类型的错误的任何建议,请提前感谢?!

Any suggestions on how to best fix these types of errors, thanks in advance?!

推荐答案

您只需要声明包含选择器的类或协议。例如:

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

然后只需 #import您计划使用的任何类中的DeliveryTimeComparison.h @selector(compareByDeliveryTime:)

或者,只需导入包含compareByDeliveryTime:方法的任何对象的类标题。

Or alternatively, just import the class header for any object that contains a "compareByDeliveryTime:" method.

这篇关于我应该修复Xcode 5'语义问题:未声明的选择器'吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:16