Save MKPolyline as NSData in NSUserDefaults

前端 未结 1 462
猫巷女王i
猫巷女王i 2021-01-21 02:28

My iOS application needs to store an MKPolyline inside of an NSUserDefault. I\'ve been doing a lot of research, and I now know that:

  • NSUs
相关标签:
1条回答
  • 2021-01-21 02:59

    While you can implement NSCoding yourself for MKPolyline, and then construct an NSData representation and store that in NSUserDefaults, it might be better to represent the MKPolyline using arrays and dictionaries, which NSUserDefaults can directly handle.

    Construct an array of dictionaries which encapsulate the x and y values for each point, and store that in NSUserDefaults instead of the MKPolyline.

    When loading defaults, get the array, loop through the dictionaries reconstructing the points, and then re-create the MKPolyline.

    0 讨论(0)
提交回复
热议问题