I’m querying rows from my sqlite database using Fetch and loading the results into a NSMutableArray myDataArray. What I want to do is to store the values in myDataArray into my application’s preferences plist file. But when I run the code below I get the following error:
[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value ‘(
…(note: contains 50 rows of values)
)’ of class ‘__NSArrayM’.
I’m storing other NSMutableArrays in my plist file using the same method but cannot figure out a way to store the queried database results.
You might ask: why store the values, just requery the database when I need the values again? The reason is I’m pulling random rows from the database and I need to recall the rows exactly as they were originally randomized.
Any help is appreciated,
lq
...
fetchResults = [managedObjectContext executeFetchRequest:request error:&error];
self.myDataArray = [NSMutableArray arrayWithArray:fetchResults];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:self.myDataArray forKey:kFetchResultsArray];
The items in myDataArray are not property list objects, so they can’t be automatically serialized to a plist.
From the NSUserDefaults class reference for
setObject:forKey::You may want to consider a mechanism other than user defaults for storing this data. From the Property List Programming Guide: