iOS*_*der 31 selector ios xcode5 semantics
我正在尝试使用Xcode5升级我的应用程序,但在第三方库(MagicalRecord)中遇到了许多"语义问题"."修复"这个的最快方法可能是使用:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
Run Code Online (Sandbox Code Playgroud)
(来自:如何摆脱'未声明的选择器'警告)
编译器指令,但我的直觉说这不是这样做的合适方式.带有上述错误的小代码示例:
+ (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];
}
}
Run Code Online (Sandbox Code Playgroud)
其中entityInManagedObjectContext:没有定义方法的地方.
有关如何最好地解决这些类型的错误的任何建议,提前谢谢?!
new*_*ima 25
是的你应该.
而不是这样做:
[self.searchResults sortUsingSelector:@selector(compareByDeliveryTime:)];
Run Code Online (Sandbox Code Playgroud)
你应该做这个:
SEL compareByDeliveryTimeSelector = sel_registerName("compareByDeliveryTime:");
[self.searchResults sortUsingSelector:compareByDeliveryTimeSelector];
Run Code Online (Sandbox Code Playgroud)
Abh*_*ert 20
您只需要声明包含选择器的类或协议.例如:
// DeliveryTimeComparison.h
#import <Foundation/Foundation.h>
@protocol DeliveryTimeComparison <NSObject>
- (void)compareByDeliveryTime:(id)otherTime;
@end
Run Code Online (Sandbox Code Playgroud)
然后只需#import "DeliveryTimeComparison.h"在您计划使用的任何课程中@selector(compareByDeliveryTime:).
或者,只需为包含"compareByDeliveryTime:"方法的任何对象导入类头.
Jas*_*ane 15
Xcode 5默认启用此功能.要关闭它,请转到"Apple LLVM 5.0 - 警告 - 目标C" - >"未声明的选择器"下目标的"构建设置",将其设置为"否".这应该照顾它.
小智 10
MagicalRecord中的这些选择器警告是为了与mogenerator生成的Core Data类兼容.除了使用mogenerator并且可能导入其中一个实体之外,除了已经回答的内容之外,你真的没什么可做的.
另一种选择当然是使用ignore块专门包围该代码
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
Run Code Online (Sandbox Code Playgroud)
最后
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)