简体   繁体   中英

Write NSMutableArray to txt file

I have an NSMutableArray of NSStrings , which I want to write to a text file, so that each string has its own line.

Any suggestions?

You can create a full string of your NSMutableArray with

- (NSString *)componentsJoinedByString:(NSString *)separator

Something like

NSString* fullString = [yourArray componentsJoinedByString:@"\n"];

You can then use

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error

on the fullString to write it on disk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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