我工作的一个应用程序与核心数据,Restkit并有一个简单的管理对象,如下的访问的NSString财产 -管理对象
@interface MyManagedObject : NSManagedObject
@property (nonatomic, strong) NSString *timeZone;
@end
我的问题是,当我尝试访问myManagedObj.timeZone ,我得到的值是 -
US/Pacific ({
HTTP = {
request = {
URL = "https://myapp.com/getTimeZone";
headers = {
Accept = "application/json";
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
"Content-Type" = "application/json; charset=utf-8";
"User-Agent" = "MyApp/204 (iPhone Simulator; iOS 7.0.3; Scale/2.00)";
};
method = POST;
};
response = {
URL = "https://myapp.com/getTimeZone";
headers = {
"Access-Control-Allow-Origin" = "*";
"Alternate-Protocol" = "443:quic";
"Cache-Control" = "no-cache";
"Content-Type" = "application/json";
Date = "Fri, 04 Apr 2014 19:11:09 GMT";
Expires = "Fri, 04 Apr 2014 19:11:09 GMT";
Vary = "Accept-Encoding";
};
};
};
mapping = {
collectionIndex = 2955515963;
rootKeyPath = "data.user_profile";
};
})
我期待的值就是“美国/太平洋”,不知道为什么HTTP请求/响应追加到它。如果我终止应用程序并重新启动它,我只会得到'美国/太平洋'。不知道为什么?
感谢您的任何帮助。
的代码来设置时区是 -
NSURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:self method:RKRequestMethodPOST path:[NSString stringWithFormat:@"/getTimeZone/%@", loginTypeString] parameters:params];
[self prioritizedRequestOperationWithRequest:request
queuePriority:NSOperationQueuePriorityVeryHigh
threadPriority:1
targetObject:self
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
myManagedObject = (MyManagedObject *)[mappingResult firstObject];
}
failure:^(RKObjectRequestOperation *operation, NSError *error, UCNetworkRequestError *ucError) {
}
useManagedRequest:YES];
下面是MyManagedObject响应映射 -
+ (RKObjectMapping *)responseMapping {
RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"MyManagedObject" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
[entityMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"timeZone"]]; // array of strings
return entityMapping;
}
你可以在设置youObject.timeZone时共享代码吗? – Krivoblotsky
更新了问题以共享数据设置的代码。 – Subhash