29

Restkit ライブラリのバージョン 0.20.3 を使用しようとしています。最近、解決方法がわからないエラーが発生しました。それは次のとおりです。

タイプ「RKObjectManager *」のオブジェクトにプロパティ「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)];

提供できる情報に感謝します。

4

6 に答える 6

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>

動かない。

于 2013-10-01T10:14:34.647 に答える
3

追加

#import <CoreData/CoreData.h>  

.pch ファイルに。

于 2013-09-29T11:22:09.993 に答える
2

この問題の根本原因は RKObjectManager.h にあります。

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

このインクルードの名前が変更されたため、RKCoreData.h が RestKit/CoreData.h に変更されているように見えるすべての場所で、この構成を使用するインクルード ファイルがいくつかあるため、グローバル検索を実行します。

于 2015-12-20T15:15:03.973 に答える