开发者

Objective C NSMutableArray removeAllObjects will also remove all strings from a file it is loaded from?

开发者 https://www.devze.com 2023-04-11 23:46 出处:网络
I have a NSMutableArray which is loaded from a txt file. There are 5 strings in the file. If Icall removeAllObjects will it remove all strings in the file?

I have a NSMutableArray which is loaded from a txt file. There are 5 strings in the file. If I call removeAllObjects will it remove all strings in the file?

I suspect it does not, so how to开发者_StackOverflow社区 remove all strings in the file?


Uh, you'd write something to the file (or simply erase it).


Your file will remain untouched by anything you do to the NSMutableArray instance you derive from it.

As to the how to remove the string, it depends on whether you want to remove just a portion of the file or delete the file. In the case of the latter, the NSFileManager method:

- (BOOL)removeItemAtURL:(NSURL *)URL error:(NSError **)error

will do what you want.

On the other hand, if you need more precise control of the file contents, you may need to drop down to C for that, fopen, etc.

0

精彩评论

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

关注公众号