ios - How to deal with CoreData save errors? -


avoiding data loss critical issue in application. need save , ensure minimal loss , immediate notification if goes wrong.

unfortunately results in lot of if (![context save:&error]) { handling on place. clean in more centralised way thought implement nsmanagedobjectcontext category method such this:

- (bool)savenotify:(nserror **)error {     nserror *saveerror;     if (![self save:&saveerror]) {          nsdictionary *userinfo = @{@"error" : saveerror};          [nsnotificationcenter.defaultcenter postnotificationname:nsmanagedobjectcontextsaveerrornotification object:self userinfo:userinfo];          if (error != null) *error = saveerror;          return no;     }     return yes; } 

now can listen notification in more general way , throw alert user if save has failed reason.

is approach or there better way deal this?

a secondary issue when occur. asking user exit app , restart bit convoluted these days need close app through task switcher.

that'll work notifying users of save errors. there couple of things keep in mind:

  1. the message in saveerror may not comprehensible users. shouldn't present it. instead, @ error code , domain , try present makes more sense.
  2. you'll need try , work out potential errors , solutions. telling users force-quit app unlikely if, example, persistent store has become corrupted or if device out of space. most save errors things come during development, if you're testing thoroughly. things validation failures or missing required values.

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -