I have an app that saves locations that a user provides by pressing on a map. The custom class looks like this:
class Places {
var name = ""
var latitude : CLLocationDegrees
var longitude : CLLocationDegrees
init(name: String, latitude: CLLocationDegrees, longitude:CLLocationDegrees) {
self.name = name
self.latitude = latitude
self.longitude = longitude
}
Then outside of the first viewController, a TableView, I set an empty array of these custom objects.
var places = [Places]()
On the next view controller, these objects are created after a long press on map.
var newPlace = Places(name: title, latitude: newCoordinate.latitude, longitude: newCoordinate.longitude)
places.append(newPlace)
The app works well but nothing gets saved when it is closed. I tried saving the array to NSUserDefaults
but apparently that can't be done with custom object arrays. What would be the most efficient way to save this array and then load it?