我一直在尝试使用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)];
感谢您所提供的任何意见!