在'RKObjectManager'types的对象上找不到属性'managedObjectStore'

我一直在尝试使用Restkit库的0.20.3版本。 最近发生了一个错误,我不知道如何解决。 它是以下几点:

在'RKObjectManager *'types的对象上找不到属性'managedObjectStore'

它发生在包含的行

objectManager.managedObjectStore = managedObjectStore;

下面列出了我的代码的一小块,以帮助识别。 我用CocoaPods来安装所有必要的库,一切似乎都正确链接。

#import "AppDelegate.h" #import <RestKit/RestKit.h> #import <RestKit/CoreData.h> #import <CoreData/CoreData.h> #import <RestKit/ObjectMapping.h> #import "Temperature.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { //let AFNetworking manage the activity indicator [AFNetworkActivityIndicatorManager sharedManager].enabled = YES; // Override point for customization after application launch. RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://grid.no-ip.biz/grid"]]; NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Grideye" ofType:@"momd"]]; //Initialize managed object store NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL ] mutableCopy]; RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; objectManager.managedObjectStore = managedObjectStore; // Setup our object mappings /** Mapping by entity. Here we are configuring a maping by targetting a Core Data entity with a specific name. This allows us to map back Sensor database objects directly onto NSManagedObject instances there is no backing model class */ RKEntityMapping *sensorMapping = [RKEntityMapping mappingForEntityForName:@"SensorID" inManagedObjectStore:managedObjectStore]; sensorMapping.identificationAttributes = @[ @"sensorID"]; [sensorMapping addAttributeMappingsFromDictionary:@{ @"sensorID" : @"sensorID", @"cellNum" : @"cellNum", @"timeStamp": @"timeStamp", @"temp" : @"temp" }]; //Update date format so that we can parse Sensor dates properly [RKObjectMapping addDefaultDateFormatterForString:@"E MMM d HH:mm:ss Z y" inTimeZone:nil]; // Register our mappings with the provider RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:sensorMapping method:RKRequestMethodGET pathPattern:@":grid" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

感谢您提供的任何input!

从0.20.1升级到0.20.3时,我遇到了同样的问题。

你需要做的是在导入RestKit之前导入CoreData。

 #import <CoreData/CoreData.h> #import <RestKit/RestKit.h> 

工作中。

 #import <RestKit/RestKit.h> #import <CoreData/CoreData.h> 

不pipe用。

添加构build设置用户标题searchpath “$ {PROJECT_DIR} / Pods”recursion。 这解决了我的情况下的问题。

在XCode6中创build新项目“pch”文件不是默认创build的,我必须在Xcode 6中的PCH文件后手动创buildpch文件

我得到它的工作在pch文件中导入标题后:

 #import <CoreData/CoreData.h> #import <RestKit/RestKit.h> 

 #import <CoreData/CoreData.h> 

到您的.pch文件。

这个问题的根源在RKObjectManager.h中

 #ifdef _COREDATADEFINES_H # if __has_include("RKCoreData.h") # define RKCoreDataIncluded # endif #endif 

这包括改变了名字,所以无处不在RKCoreData.h出现改变RestKit / CoreData.h有几个包含文件使用这个结构,所以做一个全球性的search。

如果你从0.20升级到0.26(比如升级一个多年未更新的非常古老的项目),你可能会发现以下两个build议在其他答案中是不够的:

  • 在pch中添加#import <CoreData/CoreData.h>
  • #import <CoreData/CoreData.h>之前添加#import <RestKit/RestKit.h>

相反,在您要导入restkit的相关文件的顶部,

 // Workaround for bug on RestKit 0.26.0 according to https://github.com/RestKit/RestKit/issues/2352 #ifndef RKCoreDataIncluded #define RKCoreDataIncluded #endif