i have 4 NSmutablearrays with individual data.
Now i need to save them in NSuserdefaults individually and retrieve them individually.
how can i done this,
can any one please post some code.
Thank u in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What are the contents of the arrays? While NSUserDefaults can store arrays, it only works for arrays that contain NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If there’s anything else in your array (custom objects, or other Cocoa objects besides the ones mentioned above) you can’t just put it straight into NSUserDefaults.
Assuming your objects are right, you can store the array by doing
You can get it back out again with the arrayForKey: method. Note that when you do, it will no longer be a mutable array: you can call mutableCopy on the returned array to get a mutable one. Furthermore, if you mutate the array after storing it in
NSUserDefaults, your changes will not be reflected in the app’s preferences.If you’ve got an array of objects that won’t go into NSUserDefaults (i.e. not on the list above), all is not lost: you need to look into NSCoding and archiving.