简体   繁体   English

iPhone:如何将文档目录的内容作为NSMutableArray获取?

[英]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? 如何获得NSMutableArray文档目录的内容?

I can get it as a normal NSArray, but as soon as I try to do anything with that array, my app crashes. 我可以将其作为普通的NSArray获得,但是一旦尝试对该阵列执行任何操作,我的应用就会崩溃。

Thanks 谢谢

也许这可以工作: NSMutableArray *array = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL] mutableCopy];

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? 您是否可以附加创建NSMutableArray实例的代码示例,然后再将元素插入该可变数组中?

You can't. 你不能 But you can easily create a mutable array from a non-mutable one: 但是您可以轻松地从一个非可变数组创建一个可变数组:

NSMutableArray* mutableArray = [NSMutableArray arrayWithArray: someOtherArray];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM