Question

I'm working on an app with Core data, Restkit and have a simple managed object as below -

@interface MyManagedObject : NSManagedObject
@property (nonatomic, strong) NSString *timeZone;
@end

My problem is that when I try to access myManagedObj.timeZone, the value I get is -

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";
    };
})

The value I'm expecting is just 'US/Pacific' and not sure why the HTTP request/response is appended to it. If I terminate the app and restart it, I get just 'US/Pacific'. Not sure why?

Thanks for any help.

The code to set timezones is -

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];

Below is the response mapping for MyManagedObject -

+ (RKObjectMapping *)responseMapping {
  RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"MyManagedObject" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
  [entityMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"timeZone"]]; // array of strings
  return entityMapping;
}
Was it helpful?

Solution

The log you see is from a proxy object that RestKit uses during mapping. It isn't actually saved into the store, it's just used during mapping. You don't need to worry about it as any message you send to the proxy will be forwarded to the true underlying item (the plain string in this case) - except for the description, hence you see the verbose output.

When you kill the app your are refetching the item from the data store so you get the true underlying data, minus the proxy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top