Objective C NSMutableArray removeAllObjects will also remove all strings from a file it is loaded from?
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.
精彩评论