Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write NSMutableArray to txt file

Tags:

objective-c

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?

like image 743
AMH Avatar asked Feb 22 '26 17:02

AMH


1 Answers

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.

like image 158
gcamp Avatar answered Feb 25 '26 09:02

gcamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!