dimoss dimoss - 2 months ago 20
iOS Question

How do I persist CLLocation between app launches?

I want to persist 2 CLLocations between app launches. This is the ONLY data I want stored in memory between launches. How do I go about doing this? Does CLLocation have a writetofile or store it in coredata or NSUserDefaults? I want to store the whole CLLocation object, don't want to store only lat/lon and then do more calculations etc. Thanks

Answer

Looking at the documentation I see that CLLocation implements the NSCoding protocol.

This means that you can archive and unarchive a CLLocation instance by using the NSKeyedArchiver and NSKeyedUnarchiver classes.

You can also put multiple instances of CLLocation in any container (parent) class that implements NSCoder like for example NSDictionary or NSArray and then archive or unarchive that whole collection of objects.

See the Archives and Serializations Programming Guide for more detailed info. Or post a followup question with code if you get stuck.

Comments