If you use the boiler plate template for a cocoa application that uses NSApplicationMain and several other structures needed to run the cocoa program, then you can start writing C methods without pressing objective-c. Cautions:
1) for testing purposes, it looks like this: when using xcode, it is best to start with the "Window-Based Application" template offered in the category of new iphone projects. This is a minimal template without an interface - just a window.
2) In iphone there is no "main ()" persay. You must put your code in the file "AppDelegate.m", which will actually be "[YourProjectName] AppDelegate.m". Here you will find a method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
This is a good place to call the C functions you wrote, which you can do either in this source file, or, better, in a separate file, which you #import. Please note that the application will be blocked until the completion of all your c-code.
3) No printf, I do not believe it. I'm sorry. One way to get information is to use NSLog, but expects objective-c lines to not contain C lines. Therefore, if you want to see any status from your C program, you only have to use the small objective-c bit. Corresponding line:
char *your_char_pointer =
where it converts your C-string to objective-c, which NSLog will successfully print to the console (visible using the console application in the Utility folder in OSX-based applications).
It's good?
source share