Saving Swift CLLocation in CoreData

后端 未结 3 693
梦毁少年i
梦毁少年i 2020-12-29 01:11

I am trying to save CLLocation data in Core Data. My property is set as a Transformable object.

Some sample code out there indicates one can save the lo

3条回答
  •  生来不讨喜
    2020-12-29 01:36

    This post is still helpful but a bit outdated.

    To save CLLocation I use:

    let clocation: [CLLocation]
    
    let archivedLocation = NSKeyedArchiver.archivedData(withRootObject: clocation)
    

    And to Fetch with Core Data:

    let unarchivedLocation = NSKeyedUnarchiver.unarchiveObject(with: (coreDataLocation.value(forKey: "location") as! NSData) as Data) as! CLLocation)
    

提交回复
热议问题