Use the foundation framework when writing OBJECTIVE-C programs.
What is a framework?
A framework is a library of many classes (class) that you can use to write programs.
Object (Object)
- objects can hold data and can contain a set of functions.
- The function can use the data saved by the object.
- A function that sends a message to an object that can be used to start a response.
- This type of message-based function is called method.
I. Creation of the first OBJECTIVE-C program
|
Creating a project, create a new Xcode project, OS X under Application, Command line Tool, named Firstoc, as shown in:
For files that contain object-c code, the suffix. M is generally used. Find main.m in Xcode and open and enter the following lines of code:
#import <Foundation/Foundation.h>int main (intconstChar * Argv[]) { @autoreleasepool { NSLog (@ "Hello, world! " ); *now = [NSDate date]; NSLog (@ "Thedate is%@" , now); } return 0 ;}
Build and run. The output is roughly as follows:
--Geneva- - -: -:36.130firstoc[67855:3381337] Hello, world! --Geneva- - -: -:36.135firstoc[67855:3381337] the date is --Geneva- - A: -: $+0000
NSLog () is a powerful output function provided by the foundation, which can output not only strings, but also integers, C-cell strings and Objective-c objects.
<1> its first argument is a string constant, which is populated with the corresponding variable by using the%-format placeholder in the string.
Format characters supported by the NSLog () function
| Format characters |
Description |
| D |
output integers in decimal form |
| O |
Output integers in eight binary form |
| X |
Output integers in 16 binary form |
| @ |
Output OC Object |
|
|
|
|
|
|
iOS Basics (ii) objects