-1

I'm making an app where you can keep track of the money you have. I wanted to present a log of the money added so I needed an NSMutableArray to store that information.

So what I want to know is how to store an NSMutableArray into NSUserDefaults so that I can add information to it at anytime. I've seen many questions here, but they don't help, because most of them don't talk about NSUserDefaults giving non mutable arrays.

To sum everything up, I need to dynamically add information to my array every time a method is called (saving an integer-or NSNumber) to then present it as an UITableView

José María
  • 2,835
  • 5
  • 27
  • 42
  • 2
    If you've seen other answers what part are you getting stuck on? `NSUserDefaults` will give you an immutable array. To make it mutable just call 'mutableCopy` on the array – Paul.s Mar 08 '14 at 15:48
  • possible duplicate of [insert object in an NSMutableArray saved with NSUserDefaults](http://stackoverflow.com/questions/5346395/insert-object-in-an-nsmutablearray-saved-with-nsuserdefaults) – phaxian Mar 08 '14 at 15:54

1 Answers1

0

Just fetch your (immutable) array from the defaults, then initialize the mutable array instance you're working with in your app from that using NSObjects's mutableCopy method:

  NSMutableArray *array = [arrayFromDefaults mutableCopy];

Since NSArray implements the NSMutableCopying protocol it 'knows' what its mutable counterpart is.

Jay
  • 6,572
  • 3
  • 37
  • 65