我工作的一個應用程序與核心數據,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