jake
jake

Reputation: 3

iPhone: How to get the contents of the documents directory as a NSMutableArray?

How do I get the contents of the documents directory as a NSMutableArray?

I can get it as a normal NSArray, but as soon as I try to do anything with that array, my app crashes.

Thanks

Upvotes: 0

Views: 460

Answers (3)

Stefan Arentz
Stefan Arentz

Reputation: 34935

You can't. But you can easily create a mutable array from a non-mutable one:

NSMutableArray* mutableArray = [NSMutableArray arrayWithArray: someOtherArray];

Upvotes: 0

diederikh
diederikh

Reputation: 25271

Maybe this will work: NSMutableArray *array = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL] mutableCopy];

Upvotes: 4

Rob Segal
Rob Segal

Reputation: 7625

This sounds like you might be allocating the array incorrectly. Can you attach some code samples of your creation of the NSMutableArray instance and then how you are inserting elements into that mutable array?

Upvotes: 0

Related Questions