Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
369
46
Hamburg
I have an nsarray of strings i would like to save as a text file of strings on separate lines.

I am using NSFileManager createFileAtPath, and I need to convert the NSArray into NSData first. I have tried this:

Code:
NSData *data = [NSArchiver archivedDataWithRootObject:filters];

but this doesnt give the desired results.....

here is the code i am using:

Code:
NSData *data = [NSArchiver archivedDataWithRootObject:myArray];
NSFileManager *fm = [NSFileManager defaultManager];
			[fm createFileAtPath:[savePanel filename] contents:data attributes:nil];

where myArray, is simply an array of strings.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you want just plain text, use componentsJoinedByString: to create an NSString from the array with each item separated by a new line. Then use writeToFile:atomically:encoding:error: to write it to file.
 

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
369
46
Hamburg
If you want just plain text, use componentsJoinedByString: to create an NSString from the array with each item separated by a new line. Then use writeToFile:atomically:encoding:error: to write it to file.

thanks kainjow, that worked perfectly!
:D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.