44 3. IOS SOFTWARE DEVELOPMENT TOOLS
When the app is run, the label “Hello World!” can be seen and the button gets created.
On clicking the button, nothing happens. is is because the method to handle the button press
is empty.
It is not required to know the Objective-C syntax. e item to note here is that one can
call a C function in Objective-C just by including a header. Objective-C is useful for handling
iOS APIs for sound and video i/o, whereas signal processing codes can be written in C.
3.4 IMPLEMENTING C CODES
In this section, a C code is linked to ViewController using a header file.
Right click on the HelloWorld folder in your project navigator in the left column and select
New File.
Select iOS -> Source -> C File.
Write the file name as Algorithm and select Also create a header file.
After clicking Next, select the destination to store the files. Preferably store the files in the
folder of your project.
In the project navigator, you can view the two new added files. Select Algorithm.c
In Algorithm.c, enter the following C code:
const char *HelloWorld() {
printf("Method Called");
return "Hello UTD!";
}
e function HelloWorld() 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 Objective-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 including
the header file.
..................Content has been hidden....................

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