1

Possible Duplicate:
How to store custom objects in NSUserDefaults

HI, How can i store NSMutable array in NSUserDefaults? regards shishir

Community
  • 1
  • 1
Shishir.bobby
  • 10,994
  • 21
  • 71
  • 100

1 Answers1

1

Storing the array is as easy as:

NSMutableArray *array = [NSMutableArray array];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"array"];

but every object in the array must be a property-list object. That is, they must be one of:

  • NSArray
  • NSDictionary
  • NSString
  • NSData
  • NSDate
  • NSNumber

If you want to store instances of other classes in a property list, you must create methods to serialize/deserialize them to and from one of these types. Serializing objects to dictionaries is a common approach.

EDIT: Another approach is shown here: How to store custom objects in NSUserDefaults

Community
  • 1
  • 1
Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • this is not working for me sir, i m inserting objects into an array,and i want that array should be in NSUserdefault. regards shishir – Shishir.bobby Jun 07 '10 at 11:50