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

时间:2013-09-16 02:31:27

标签: ios restkit restkit-0.20

我一直在尝试使用Restkit库的0.20.3版本。最近出现了一个错误,我无法弄清楚如何解决。它是以下内容:

  

Property' managedObjectStore'在类型的对象上找不到   ' RKObjectManager *'

它发生在包含

的行

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

感谢您提供的任何输入!

6 个答案:

答案 0 :(得分:73)

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

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

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

正在运作。

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

无效。

答案 1 :(得分:26)

添加构建设置用户标题搜索路径 &#34; $ {PROJECT_DIR} / Pods&#34; 递归。这解决了我的问题。

答案 2 :(得分:4)

在XCode6中创建新项目&#34; pch&#34;文件默认不创建,我必须在PCH File in Xcode 6后手动创建pch文件

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

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

答案 3 :(得分:3)

添加

#import <CoreData/CoreData.h>  

到您的.pch文件。

答案 4 :(得分:2)

此问题的根本原因在于RKObjectManager.h

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

这个包含已更改的名称,所以RKCoreData.h出现的任何地方都改为RestKit / CoreData.h,有几个包含使用此结构的包含文件,所以进行全局搜索。

答案 5 :(得分:0)

如果您要从0.20升级到0.26(例如,升级一个多年未更新的非常旧的项目),您可能会发现其他答案中建议的以下两项都不充分:

  • 在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