How is an array saved to NSUserDefaults?
I have the following code which tries to store an array of NSURLs
NSArray *temp = [[NSArray alloc] initWithArray:[mySingleton sharedMySingleton].sharedURLS];
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
[defs setObject:temp forKey:@"URLs"];
but I get a warning
-[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value
What is the correct way to store this or collection of NSURLS?
You can't directly store an NSURL
in NSUserDefaults
, only NSData
, NSString
, NSNumber
, NSDate
, NSArray
, or NSDictionary
; also, any NSArray
or NSDictionary
may only contain objects of these types. You'll have to convert the NSURLs into one of these types, most likely by using absoluteString to convert them into NSStrings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With