I have an array of NSURL items like this:
var array = [NSURL]()
I'm trying to save this to NSUserDefaults:
let defaults = NSUserDefaults(suiteName: "group.a.project")
defaults?.setObject(array, forKey: "NSURLarray")
Will result in it crashing as NSURL can't be stored in NSUserDefaults.
How can I save this array of NSURL's to NSUserDefaults, so that I can then access it and use the NSURL's in the array as required (saving an array of strings and then trying to use them as NSURL's will result in an error from xcode)?
when saving, save the absolute strings of the urls. when loading use NSURL(URLString:) to make the strings into urls again
saving can be reduced with KVC.
You could archive your URL array to an instance of NSData and store that in user defaults. To save:
To load: