swift - Core Data: Add a column on a table -
i want add column on table new version of app, , keep filled columns. work core data, momd:
on appdelegate:
/* core data */ // mark: - core data stack lazy var applicationdocumentsdirectory: nsurl = { let urls = nsfilemanager.defaultmanager().urlsfordirectory(.documentdirectory, indomains: .userdomainmask) return urls[urls.count-1] }() lazy var managedobjectmodel: nsmanagedobjectmodel = { let modelurl = nsbundle.mainbundle().urlforresource("solutis", withextension: "momd")! return nsmanagedobjectmodel(contentsofurl: modelurl)! }() lazy var persistentstorecoordinator: nspersistentstorecoordinator = { let coordinator = nspersistentstorecoordinator(managedobjectmodel: self.managedobjectmodel) let url = self.applicationdocumentsdirectory.urlbyappendingpathcomponent("solutis.sqlite") var failurereason = "there error creating or loading application's saved data." { try coordinator.addpersistentstorewithtype(nssqlitestoretype, configuration: nil, url: url, options: nil) } catch let error nserror { var dict = [string: anyobject]() dict[nslocalizeddescriptionkey] = "failed initialize application's saved data" dict[nslocalizedfailurereasonerrorkey] = failurereason dict[nsunderlyingerrorkey] = error let wrappederror = nserror(domain: "your_error_domain", code: 9999, userinfo: dict) nslog("unresolved error \(wrappederror), \(wrappederror.userinfo)") abort() } catch { fatalerror() } return coordinator }() lazy var managedobjectcontext: nsmanagedobjectcontext = { let coordinator = self.persistentstorecoordinator var managedobjectcontext = nsmanagedobjectcontext(concurrencytype: .mainqueueconcurrencytype) managedobjectcontext.persistentstorecoordinator = coordinator return managedobjectcontext }() // mark: - core data saving support func savecontext () { if managedobjectcontext.haschanges { { try managedobjectcontext.save() } catch { let nserror = error nserror nslog("unresolved error \(nserror), \(nserror.userinfo)") abort() } } }
so if user update app filled table, gonna keep data , have new version of table.
but how ? juste learned add model version, how retrieve old data ?
Comments
Post a Comment