ios - undeclared type 'NSPersistenContainer' -
i'm insert in xcode project (swift 2.2 , xcode 7.2.1) code appdelegate file coredata.
lazy var persistentcontainer: nspersistentcontainer = { /* persistent container application. implementation creates , returns container, having loaded store application it. property optional since there legitimate error conditions cause creation of store fail. */ let container = nspersistentcontainer(name: "arduinohomekit") container.loadpersistentstores(completionhandler: { (storedescription, error) in if let error = error nserror? { // replace implementation code handle error appropriately. // fatalerror() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. /* typical reasons error here include: * parent directory not exist, cannot created, or disallows writing. * persistent store not accessible, due permissions or data protection when device locked. * device out of space. * store not migrated current model version. check error message determine actual problem was. */ fatalerror("unresolved error \(error), \(error.userinfo)") } }) return container }() func savecontext () { let context = persistentcontainer.viewcontext if context.haschanges { { try context.save() } catch { // replace implementation code handle error appropriately. // abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. let nserror = error nserror nslog("unresolved error \(nserror), \(nserror.userinfo)") abort() } } }
but have error on nspersistentcontainer. error is:
could not infer type 'persistentcontainer'
use of undeclared type 'nspersistencontainer'
i think problem because code swift 3.0 have used swift 2.2 how can fixed it?
nspersistentcontainer
added in ios 10. using xcode 7.2.1 means base sdk ios 9. therefore nspersistentcontainer
unknown class.
use older examples core data existed prior ios 10 , nspersistentcontainer
.
or update xcode 8.3 , ios 10 (which should anyway). if deployment target ios 9 or earlier, need aware app won't work on device if try use nspersistentcontainer
.
Comments
Post a Comment