Hi, is there a way to write files to the iphone file system using only pure c code and some posix like api?
I only found some Objective-C/Cocoa stuff out there and I think that I can't just mix some Objective-C code snippet into the .c file.
Hi, is there a way to write files to the iphone file system using only pure c code and some posix like api?
I only found some Objective-C/Cocoa stuff out there and I think that I can't just mix some Objective-C code snippet into the .c file.
Objective-C is a layer built on top of the C language; so potentially anything that's written in C or anything that's in the Standard C library can be called in your Objective-C code.
For file IO, you can use the standard C file IO:
NSString *filePath = @"YOUR FILE PATH";
FILE *file;
file = fopen([filePath cStringUsingEncoding:NSUTF8StringEncoding], "w");
fprintf(file, "YOUR OUTPUT HERE\n");
fclose(file);
Objective C is a pure superset of plain ANSI C. You can just drop any pure C code into any Objective C .m file. (The opposite won't work because the compiler won't know to compile a .c file using the language superset.)
Added: The way to do it the other way around is not to try and directly put Objective C in a C file, but to put the Objective C in a new Objective C .m file with a C wrapper function to call that Objective C method also in that .m file. Then use a C function call in the C file to call from that C file to the Objective C file's C wrapper function, and have that C wrapper function in the Objective C file call the Objective C method.
Most C posix calls work normally on the iPhone, although some are illegal if they try to reach outside the security sandbox (e.g. you may have to use a bit of Objective C to determine which legal file paths the posix fopen() call can use.)
I've taken large C apps and wrapped them up in just enough Objective C to connect them with the Cocoa Touch UI framework. A few pages worth.