gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:49:22 26 4
gpt4 key购买 nike

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

Property 'managedObjectStore' not found on object of type '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)];

感谢您提供的任何意见!

最佳答案

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

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

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

正在工作。

但是

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

不工作。

关于ios - 在 'managedObjectStore' 类型的对象上找不到属性 'RKObjectManager',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18819652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com