ios - Why is my app crashing on iPhone 4S because of Core Data request execute? -


i have app works fine on simulator 6.1, works fine on iphone5 , ipad3 on ios6.1 when run on iphone4s crashes in method exc bad access:

-(void)parseplistintocd{     self.managedobjectcontext = [[sdcoredatacontroller sharedinstance] backgroundmanagedobjectcontext];     // 3: put plistdictionary cd...create managedobjectcontext     nsmanagedobjectcontext *context = self.managedobjectcontext;     nserror *error;      //create request & set entity request     nsfetchrequest *holidayrequest = [[nsfetchrequest alloc] init];     nsentitydescription *topicentitydescription = [nsentitydescription entityforname:@"holiday" inmanagedobjectcontext:context];     [holidayrequest setentity:topicentitydescription];      //create new nsmanagedobject     //holiday *holidayobjecttoseed = nil;     holiday *newholiday = nil;     //execute fetch make sure?     nsarray *holidayfetchedarray = [context executefetchrequest:holidayrequest error:&error];     **if (error) nslog(@"error encountered in executing topic fetch request: %@", error); // if comment line out reaches far next bold line**      // no holidays in database proceed populate database     if ([holidayfetchedarray count] == 0) {         //get path plist file         nsstring *holidayspath = [[nsbundle mainbundle] pathforresource:@"preloadedfarsiman" oftype:@"plist"];         //put data array (with dictionaries in it)         nsarray *holidaydataarray = [[nsarray alloc] initwithcontentsoffile:holidayspath];         **nslog(@"holidaydataarray %@", holidaydataarray);**         //get number of items in array         int numberoftopics = [holidaydataarray count];         //loop thru array items...         (int = 0; i<numberoftopics; i++) {             //get each dict @ each node             nsdictionary *holidaydatadictionary = [holidaydataarray objectatindex:i];             //insert new object             newholiday = [nsentitydescription insertnewobjectforentityforname:@"holiday" inmanagedobjectcontext:context];             //parse keys in each dict object             [newholiday setvaluesforkeyswithdictionary:holidaydatadictionary];             //save , or log error             [context save:&error];             if (error) nslog(@"error encountered in saving topic entity, %d, %@, hint: check structure of plist matches core data: %@",i, newholiday, error);         };     }      //set bool specifies coredata has been populated plist     nsstring *bundleversion = [[nsbundle mainbundle] objectforinfodictionarykey:(nsstring *)kcfbundleversionkey];     nsstring *appfirststartofversionkey = [nsstring stringwithformat:@"first_start_%@", bundleversion];      nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults];     [prefs setobject:@(yes) forkey:appfirststartofversionkey];     [prefs synchronize]; } 

why on 4s? gives no console log , last know method traversed in 1 above. here pic:

enter image description here

and mentioned above, if uncomment nslog line reaches far logging array, shown in pic. if leave in stops @ line.

nsarray *holidayfetchedarray = [context executefetchrequest:holidayrequest error:&error]; if (error)     nslog(@"error encountered in executing topic fetch request: %@", error); 

no no no no no. know difficult pattern, please let's try right. not if (error). error (esp. under non-arc). test if (!holidayfetchedarray).

for all of these methods return value , take nserror** indirection, test result see if nil. if is, there error because returning nil sign there error. , may touch error meaningfully.

the docs quite clear this, though true fog can come on one's eyes @ critical instance, i've added comments in italic brackets call out key points:

request

a fetch request specifies search criteria fetch.

error

if there problem executing fetch, upon return contains instance of nserror describes problem. [and if there no problem executing fetch, contains garbage don't touch it!]

return value

an array of objects meet criteria specified request fetched receiver , persistent stores associated receiver’s persistent store coordinator. if error occurs, returns nil. [and that, forsooth, sign error did occur.] if no objects match criteria specified request, returns empty array.

this might cause of trouble or might not, must fix now. want go through code looking nserror* variables declared use in pattern , fix all of them! thank you. here endeth lesson.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -