46 2. SOFTWARE DEVELOPMENT TOOLS
• e function HellowWorld() prints a string and returns a char pointer upon execution.
Let us call this function on the button press action in the view controller and alter the
label.
• To allow this function to be called in Objectve-C, the function in the header file needs to
be declared. For this purpose, in Algorithm.h, add the following line before #endif :
const char *HelloWorld();
• Now a C function is created, which is called and executed via Objective-C, just by includ-
ing the header file.
2.2.5 EXECUTING C CODES VIA OBJECTIVE-C
Now that a C code is written, it needs to be linked to the Objective-C app in order to be
executed.
• In the ViewController.m, just below #import ``ViewController.h'', add
#import ``Algorithm.h''
• In the buttonPress method, include the following line:
_label.text = [NSString stringWithUTF8String:HelloWorld()];
is code line alters the text of the label in the program.
• Run the program using the simulator.
1. e text of the label changes.
2. In the Xcode window, “Method Called” gets printed in the Debug Console at the bottom.
is shows that printing can be done from the C function to the debug console in Xcode. is
feature is used for debugging purposes.
2.2.6 iOS APP DEBUGGING
After getting some familiarity with the Xcode IDE by creating and modifying an iOS app project
and running the app on an iPhone simulator, the following steps indicate how to debug C codes
via the built-in Xcode debugger.
To obtain familiarity with the Xcode debugging tool, perform the following:
• Open the HelloWorld project.
• Select Product ! Build.
• In the project navigator, select the Algorithm.c file.