iosswiftcore-datacllocationcoordinate2d

How to store an array of CLLocationCoordinate2D in Core Data to draw a polyline?


I want to store an array of CLLocationCoordinate2D in Core Data but this error always appears while executing the code xcode screenshot

Thread 1: signal SIGABRT


Solution

  • As the error says in the console:

    this archiver cannot encode structs

    CLLocationCoordinate2D is a struct. Core Data can only store basic types like dates, numbers, data, strings etc. If you want to store a location coordinate just store its components (simply latitude and longitude) as doubles, and you can write a supporting method to initialize the CLLocationCoordinate2D struct from the numerical values.