我正在开发一个IO项目,我正在使用'RestKit','〜> 0.20.0rc”。
我遇到有关存储在我的数据库中的对象列表的问题。
当我从我的服务器获得一个新列表并尝试更新现有的列表时,我注意到我的数据库中的对象与我从服务器获取的对象具有类似的主键是那些没有更新。
但正在添加新对象(数据库中尚未存在),我按照文档进行操作,但仍然没有任何更改,也没有更新。
我正在使用:identificationAttributes = @ [@“objectId”]所以我不会有重复的对象。
有什么问题?在Restkit版本中?
谢谢!
配置映射方法:
- (void)configure
{
RKEntityMapping *storeMapping = [self mappingStore];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:storeMapping method:RKRequestMethodGET pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
}
StoreMapping:
- (RKEntityMapping *)mappingStore {
RKEntityMapping *storeMapping = [RKEntityMapping mappingForEntityForName:@"Store" inManagedObjectStore:managedObjectStore];
[storeMapping addAttributeMappingsFromDictionary:Store.mapDictionary];
storeMapping.identificationAttributes = @[ @"storeId" ];
return storeMapping;
}
地图字典:
+(NSDictionary *)mapDictionary{
return @{
@"id": @"storeId",
@"name_en": @"nameEn",
@"description_en": @"descriptionEn",
@"address_en": @"addressEn",
@"latitude": @"latitude",
@"longitude": @"longitude",
@"phone": @"phone",
@"email": @"email",
@"disponibility_en": @"disponibilityEn",
@"images": @"images",
};
}
加载商店:
- (void)loadStores
{
[self configure];
[objectManager getObjectsAtPath:@"stores" parameters:@{} success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[[NSNotificationCenter defaultCenter] postNotificationName:Store.requestGetStoreSuccess object:mappingResult];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
[[NSNotificationCenter defaultCenter] postNotificationName:Store.requestGetStoreFailure object:operation];
NSLog(@"________________________error?': %@", error);
}];
}
Json我收到了:
[
{
id: 6,
name_en: "Market Center Dubaï 0",
description_en: "Tenetur consectetur et et rerum alias iste molestiae qui excepturi architecto aut. Ex doloremque repellat labore doloribus minima totam voluptas accusamus minima sint animi consequatur. Voluptatibus voluptatem ducimus expedita autem suscipit et provident sunt deserunt laborum omnis blanditiis est illo aut ea unde consequatur maxime. Iste molestiae sed ut est aut enim voluptas praesentium molestiae earum molestias nihil tenetur et ea error itaque nobis eius. Voluptas voluptatum est ab molestias explicabo quas modi natus tenetur consectetur consectetur veritatis omnis veritatis aut quis doloribus maxime",
address_en: "45 Reward St, 12340, Dubaï",
latitude: 25.2048493,
longitude: 55.2707828,
phone: "0011223344",
email: "contact@mail.com",
disponibility_en: "10h-18h Mon, Thu, Wed, Tue",
images: [ ]
}, ...
这些是CoreData和Mapping的日志,我在我的数据库中有一个带有“name_en”=“Market Center Dubai 2”的对象,我把它更改为name_en“=”市场中心迪拜2 ___ 5“n在日志中,RestKit检测到其他属性没有改变,它在日志中写入:值未更改,但它检测到我更改了“name_en”,仍然id不执行更新:
2015-01-12 16:49:40.802 Project[16928:766909] D restkit.core_data:RKFetchRequestManagedObjectCache.m:124 Found objects '(
"<Store: 0x7f889d8bd3c0> (entity: Store; id: 0xd000000000080002 <x-coredata://444E828C-7F64-4864-9EEB-09AE68872436/Store/p2> ; data: <fault>)"
)' using fetchRequest '<NSFetchRequest: 0x7f889de36700> (entity: Store; predicate: (storeId == 8); sortDescriptors: ((null)); type: NSManagedObjectResultType; )'
2015-01-12 16:49:40.803 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:869 Performing mapping operation: <RKMappingOperation 0x7f889c45e4f0> for 'Store' object. Mapping values from object {
"address_ar" = "";
"address_en" = "45 Reward St, 12342, Duba\U00ef";
"description_ar" = "";
"description_en" = "Reiciendis rerum praesentium omnis in explicabo doloremque eum aut enim dolores quis. Numquam vel dolorem quis tenetur ut perspiciatis reiciendis aliquam autem iure et expedita quam illo et consectetur nesciunt. Qui sed vel enim dolores ullam et rem recusandae est ut nisi numquam laudantium. Rerum inventore numquam dolores sapiente autem quo natus qui. Quia ab suscipit omnis dignissimos sunt eum nesciunt molestiae maiores est non ut. Ut voluptates minima modi delectus voluptates et rerum consectetur quis tempore sunt quaerat nam et non ut rerum dolores. Unde sed alias consectetur minima accusamus et eum mollitia mollitia expedita facilis deleniti. Animi non et repudiandae maxime ut quia voluptas possimus corrupti odit enim quia voluptas veniam labore";
"disponibility_ar" = "";
"disponibility_en" = "10h-18h Mon, Thu, Wed, Tue";
email = "contact@email.com";
id = 8;
images = (
);
latitude = "25.2048493";
longitude = "55.2707828";
"name_ar" = "";
"name_en" = "Market Center Duba\U00ef 2____5";
phone = 0011223344;
} to object <Store: 0x7f889d8bd3c0> (entity: Store; id: 0xd000000000080002 <x-coredata://444E828C-7F64-4864-9EEB-09AE68872436/Store/p2> ; data: <fault>) with object mapping (null)
2015-01-12 16:49:40.803 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:447 Found transformable value at keyPath 'address_en'. Transforming from class '__NSCFString' to 'NSString'
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:462 Mapping attribute value keyPath 'address_en' to 'addressEn'
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:493 Skipped mapping of attribute value from keyPath 'address_en to keyPath 'addressEn' -- value is unchanged (45 Reward St, 12342, Dubaï)
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:447 Found transformable value at keyPath 'phone'. Transforming from class '__NSCFString' to 'NSString'
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:462 Mapping attribute value keyPath 'phone' to 'phone'
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:493 Skipped mapping of attribute value from keyPath 'phone to keyPath 'phone' -- value is unchanged (0011223344)
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:447 Found transformable value at keyPath 'name_en'. Transforming from class '__NSCFString' to 'NSString'
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:462 Mapping attribute value keyPath 'name_en' to 'nameEn'
2015-01-12 16:49:40.804 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:478 Mapped attribute value from keyPath 'name_en' to 'nameEn'. Value: Market Center Dubaï 2____5
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:447 Found transformable value at keyPath 'id'. Transforming from class '__NSCFNumber' to 'NSNumber'
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:462 Mapping attribute value keyPath 'id' to 'storeId'
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:493 Skipped mapping of attribute value from keyPath 'id to keyPath 'storeId' -- value is unchanged (8)
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:447 Found transformable value at keyPath 'longitude'. Transforming from class '__NSCFNumber' to 'NSDecimalNumber'
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:462 Mapping attribute value keyPath 'longitude' to 'longitude'
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:493 Skipped mapping of attribute value from keyPath 'longitude to keyPath 'longitude' -- value is unchanged (55.2707828)
2015-01-12 16:49:40.805 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:447 Found transformable value at keyPath 'images'. Transforming from class '__NSArrayI' to 'NSArray'
2015-01-12 16:49:40.806 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:462 Mapping attribute value keyPath 'images' to 'images'
2015-01-12 16:49:40.806 Project[16928:766909] T restkit.object_mapping:RKMappingOperation.m:493 Skipped mapping of attribute value from keyPath 'images to keyPath 'images' -- value is unchanged ((
))