after app restarted data core-data not returned properly. , fetch request particular record fails. fetchrequestcontroller not grabs record once app re-started.
i using encrypted-core-data protect data in project. able parse , save data managedobjectcontext. code looks this
for (nsdictionary *data in categories) { //use magicrecord api record cmcategories *obj = [cmcategories mr_findfirstbyattribute:@"uniqueid" withvalue:[data valueforkey:@"id"] incontext:managedobjectcontext]; if (!obj) { obj = [cmcategories mr_createentityincontext:managedobjectcontext]; } obj.name = [data valueforkey:@"categoryname"]; obj.language = [data valueforkey:@"languagecode"]; obj.uniqueid = [data valueforkey:@"id"]; } nserror *error = nil; if (![_managedobjectcontext save:&error]) { nslog(@"error saving context: %@\n%@", [error localizeddescription], [error userinfo]); abort(); }
the code works without error. persistentstorecoordinator
, managedobjectcontext
code same this
when print obj before closing app prints
2016-01-24 23:59:11.806 chare dev[10556:158617] <cmcategories: 0x7feb00d24a90> (entity: cmcategories; id: 0x7feb02ef5890 <x-coredata://b947acd3-e248-4d4f-b81e-236e100bb34d/cmcategories/p5> ; data: { channels = ( ); language = en; name = professional; order = 0; uniqueid = 15; })
but after app restart, when fetch objects , print prints this
2016-01-24 23:59:11.795 chare dev[10556:158617] <cmcategories: 0x7feb02de4aa0> (entity: cmcategories; id: 0x7feb02de5c10 <x-coredata://b947acd3-e248-4d4f-b81e-236e100bb34d/cmcategories/p2> ; data: { channels = "<relationship fault: 0x7feb02922450 'channels'>"; language = nil; name = nil; order = nil; uniqueid = nil; })
and if try property nsstring *string = obj.uniqueid
2016-01-24 23:59:11.795 chare dev[10556:158617] coredata: warning: nsmanagedobjectcontext delegate overrode fault handling behavior silently delete object id '0x7feb02de5c10 ' , substitute nil/0 property values instead of throwing
if use nssqlitestoretype
instead of encryptedstoretype
works fine. can guide me doing wrong?
because due above issue, database records added multiple times , fetch request fails fetch managed object uniqueid.
tl;dr
don't use sqlite keywords on model (properties, relationships, entities, etc).
usually coredata safe use sqlite reserved keywords, apparently not case when using encryptedcoredata.
this #232 issue explains well.
in project had from
property of 1 of models, , single property culprit.
i can see code:
2016-01-24 23:59:11.806 chare dev[10556:158617] <cmcategories: 0x7feb00d24a90> (entity: cmcategories; id: 0x7feb02ef5890 <x-coredata://b947acd3-e248-4d4f-b81e-236e100bb34d/cmcategories/p5> ; data: { channels = ( ); language = en; name = professional; order = 0; uniqueid = 15; })
you using order
, keyword. try remove , check.
note: after renaming property model had uninstall , install app again, not of hassle me since not published yet.
Comments
Post a Comment