I followed the tutorial: Working with iCloud: Document Storage to implement the support for saving the objects of an Array to iCloud by turning them into a UIDocument subclass. I have not yet tried whether the iCloud implementation works, but testing it on the simulator without iCloud does nothing as baseURL is nil and nothing happens in that case. This is my Swift implementation for the create operation:
func newFavorite(favorite: palinaModel) ->Bool {
if indexForPalina(favorite) != nil {
print("stop already favorite")
return false;
}
/
let baseURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)
if (baseURL != nil) {
let documentsURL = baseURL!.URLByAppendingPathComponent("Documents")
let documentURL = documentsURL.URLByAppendingPathComponent(String(format:"Stop_%@-%f", favorite.palina, NSDate()))
let document = FavoriteStopDocument(fileURL:documentURL)
document.favoriteStop = favorite;
/
self.favoriteStops.append(document)
/
document.saveToURL(documentURL, forSaveOperation:.ForCreating, completionHandler:{(success) in
if (success) {
print("Save succeeded.");
} else {
print("Save failed.");
}
})
}
return true
}
How do I change it to also handle the case in which iCloud is not available? For the time begin I may skip the case in which iCloud gets enabled after some local information is created.
Thanks for you support,