How to store CLLocation using Core Data (iPhone)?

前端 未结 5 1901
故里飘歌
故里飘歌 2021-01-30 01:41

I\'m trying to save a location and retrieve the location on a map afterward using Core Location, MapKit and Core Data frameworks.

What I\'ve done is I just made entity

5条回答
  •  一生所求
    2021-01-30 02:17

    CLLocation implements the NSCoding protocol so you can store them in Core Data as transformable attributes. You can use the default NSKeyedUnarchiveFromData value transformer.

    You would just pass the CCLocation object to the managed object attribute and it would serialize it to data and store it as a blob in the SQL store. When you need the location object back it would automatically reverse the process and return to you a fully populated CCLocation object.

    That might be the easiest way to get what you want.

提交回复
热议问题