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.
2.2. iOS TOOLS INSTALLATION STEPS 47
After the project is successfully built, so-called debug points can be placed inside the C
code. Debug points can be placed by clicking on the column next to the line to be debugged or
by pressing CMD C . A blue arrow appears, see Figure 2.31, that points toward the line to be
debugged.
Figure 2.31: A debug point added on line 12.
e Xcode debugger allows one to:
pause the execution at a particular line of code,
know the value of the variable at that particular instant of execution, and
navigate from the function call to function execution as it gets executed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.231.155