开发者

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

开发者 https://www.devze.com 2022-12-23 05:50 出处:网络
How do I get the contents of the documents directory as a NSMutableA开发者_开发技巧rray? I can get it as a normal NSArray, but as soon as I try to do anything with that array, my app crashes.

How do I get the contents of the documents directory as a NSMutableA开发者_开发技巧rray?

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

Thanks


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


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

NSMutableArray* mutableArray = [NSMutableArray arrayWithArray: someOtherArray];


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号