Restkit + Core Data: Inserts duplicate values in a UITableView on every app launch -
following alexedge tutorial have encountered following behavior. can provide code requested since there many lines , i'm not sure look. basically, "works" in sense data loaded uitableview, after stopping , starting simulator, inserts new duplicate rows in each section.
i figured have caching following above tutorial pretty closely , i've set identificationattributes
identify unique records (wouldn't, example, adding attributes eliminate possibility i've not specified sufficiently unique key, debugging purposes?). i've tried changing cache name, setting nil, keeps inserting duplicates. every reset simulator start on clean slate.
if matters, calling getobjectsatpath
in viewdidload
per tutorial. understanding of how restkit worked was okay because smart enough infer no updates necessary records same.
edit
i have set identificationattributes
array of 2 integer attributes determine unique record.
i have managedobjectcache
:
// seal deal [managedstore createpersistentstorecoordinator]; nsstring *storepath = [rkapplicationdatadirectory() stringbyappendingpathcomponent:@"cctdb.sqlite"]; nserror *error; nspersistentstore *persistentstore = [managedstore addsqlitepersistentstoreatpath:storepath fromseeddatabaseatpath:nil withconfiguration:nil options:@{ nsmigratepersistentstoresautomaticallyoption:@yes, nsinfermappingmodelautomaticallyoption:@yes } error:&error]; nsassert(persistentstore, @"failed add persistent store error: %@", error); [managedstore createmanagedobjectcontexts]; managedstore.managedobjectcache = [[rkinmemorymanagedobjectcache alloc] initwithmanagedobjectcontext:managedstore.persistentstoremanagedobjectcontext];
edit 1
here log output of second time around
(2013-07-11 03:18:29.961 cocoaclinical[18773:3d07] d restkit.object_mapping:rkpropertyinspector.m:130 cached property inspection class 'emdisease': { diseaseid = { isprimitive = 0; keyvaluecodingclass = nsnumber; name = diseaseid; }; diseaseidvalue = { isprimitive = 1; keyvaluecodingclass = nsnumber; name = diseaseidvalue; }; name = { isprimitive = 0; keyvaluecodingclass = nsstring; name = name; }; subdiseaseid = { isprimitive = 0; keyvaluecodingclass = nsnumber; name = subdiseaseid; }; subdiseaseidvalue = { isprimitive = 1; keyvaluecodingclass = nsnumber; name = subdiseaseidvalue; }; } 2013-07-11 03:18:29.975 cocoaclinical[18773:3f03] restkit.core_data:rkinmemorymanagedobjectcache.m:94 caching instances of entity 'emdisease' attributes 'diseaseid, subdiseaseid' 2013-07-11 03:18:29.983 cocoaclinical[18773:3f03] t restkit.core_data:rkinmemorymanagedobjectcache.m:127 cached 31 objects 2013-07-11 03:18:29.984 cocoaclinical[18773:3f03] d restkit.object_mapping:rkmapperoperation.m:231 asked map source object { diseasesystemidmember = 161; displaynamemember = "acute lymphocytic leukemia"; subdiseasesystemidmember = 1886; } mapping <rkentitymapping:0x96c2850 objectclass=emdisease propertymappings=( "<rkattributemapping: 0x96ba060 subdiseasesystemidmember => subdiseaseid>", "<rkattributemapping: 0xb58df40 displaynamemember => name>", "<rkattributemapping: 0xb58df70 diseasesystemidmember => diseaseid>" )> 2013-07-11 03:18:29.984 cocoaclinical[18773:3f03] d restkit.object_mapping:rkmappingoperation.m:952 starting mapping operation... 2013-07-11 03:18:29.985 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:953 performing mapping operation: <rkmappingoperation 0xb5b7820> 'emdisease' object. mapping values object { diseasesystemidmember = 161; displaynamemember = "acute lymphocytic leukemia"; subdiseasesystemidmember = 1886; } object <emdisease: 0xb5b7ee0> (entity: emdisease; id: 0xb5b7f80 <x-coredata:///emdisease/t8dd8ee18-c798-468f-9e03-c6a3c724aa772> ; data: { diseaseid = 161; name = nil; subdiseaseid = 1886; }) object mapping (null) 2013-07-11 03:18:30.027 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:550 mapping attribute value keypath 'subdiseasesystemidmember' 'subdiseaseid' 2013-07-11 03:18:30.028 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:583 skipped mapping of attribute value keypath 'subdiseasesystemidmember keypath 'subdiseaseid' -- value unchanged (1886) 2013-07-11 03:18:30.029 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:550 mapping attribute value keypath 'displaynamemember' 'name' 2013-07-11 03:18:30.029 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:572 mapped attribute value keypath 'displaynamemember' 'name'. value: acute lymphocytic leukemia 2013-07-11 03:18:30.030 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:550 mapping attribute value keypath 'diseasesystemidmember' 'diseaseid' 2013-07-11 03:18:30.030 cocoaclinical[18773:3f03] t restkit.object_mapping:rkmappingoperation.m:583 skipped mapping of attribute value keypath 'diseasesystemidmember keypath 'diseaseid' -- value unchanged (161) 2013-07-11 03:18:30.031 cocoaclinical[18773:3f03] d restkit.object_mapping:rkmappingoperation.m:1021 finished mapping operation successfully...
you need set identificationattributes
, 1 or 2 attributes though, not everything. entities should have unique identifier.
you want add managedobjectcache
managed object store. part allows restkit match objects using identificationattributes
, update existing items instead of creating new ones.
Comments
Post a Comment