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

Fritzables

macrumors regular
Original poster
May 6, 2011
149
1
Brisbane AUSTRALIA
I want to write some data to a disk file. Nothing major, just ASCII data to a 'txt' file.

Would I just use the good ol'e 'fout' as you would in 'C' or is it best to use NSOutputStream?

I am using XCode4 and Cocoa.

Pete
 
Where is the data? If it's in an NSString or NSData object, then those classes contain routines to write the data to a file.

If the data isn't in an Objective-C class, then I would probably end up writing the data using normal C stdio routines.
 
The data is within a SQLITE3 database.
I am writing a HAM Radio Contest Logging app and when the contest is complete one needs to submit a LOG of all contacts as an ASCII file as proof.

Pete
 
Break the problem down.

First, get the data out of the sql database.

If it's in C string form, then you already have it in a form you can used fprintf() on.

If the data isn't in C strings, what form is it in? Simple C types like int or float? You can still use fprintf().

If the data is in NSString or NSNumber form, then look at those classes and find methods that convert to C strings (for NSString) or simple C types (for NSNumber). Then you can use fprintf().

SInce Objective-C is a superset of plain ordinary C, you can use every C function the same way. If you already know C's stdio functions, then save yourself the trouble and just use what you know.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.