Objective-C learning one

1. OC is relative to C

  • a. On the basis of C, a small part of the syntax of surface line objects has been added.

  • b. It is simpler to encapsulate the complex and cumbersome syntax of C.

  • c. OC is fully compatible with C language.

2. The suffix of the source file of the OC program is .mm for message, which represents the most important mechanism in OC. The suffix of the source file of the C program.c

3. The main function is still the if and exit of the OC program.
The return value of type int represents the end state of the program.
Parameters of the main function: It is still acceptable for the user to pass data to the program when running the program. Parameters can also be omitted
4. #import directive

  • 1), starting with #, is a preprocessing instruction.

  • 2) Function: It is an enhanced version of the #inlcude command. Copy the content of the file to the place where the instruction is written during precompilation.

  • 3) Enhancement: No matter how many times #import the same file, it will only be included once.

5. Framework

  • 1) It is a collection of functions. Apple or a third party writes some functions that are often used when developing programs in advance, and writes these functions in advance. Encapsulate these functions in one class or function. A collection of classes of these functions is called a framework.
  • 2), Foundation framework. foundation: basic foundation. Some of the most basic functional inputs and outputs are provided in this framework. some data types. #import <Foundation/Foundation.h>

6. @autoreleasepool is an autorelease pool, you can write code in the autorelease pool or simply delete the autorelease pool.
7. NSLog function.

  • 1) Function: It is an enhanced version of the printf function. Output information to the console.
  • 2) Syntax: NSLog(@"Format control string", variable list); The simplest syntax: NSLog(@"Information to be output");
  • 3), Enhancement: a. Output some debugging related information, time , program name, process number, thread number, output information , etc. b. It will automatically wrap
  • 4), usage
float f1 = 12.12f;
NSLog(@"jack f1 = %f",f1);

8. String
1), NSString in OC The character needle variable of NSString type is specially used to store the address of OC string.
2), OC string constants must use a prefix @ symbol.
"jack" C language string
@"jack" OC string
NSString type pointer variable, which can only store OC string address.
NSString *str = @“jack”;
9. Function definition and call.
The definition and call of the function in C language are the same

void test();

int main()
{
test();

return 0;
}

void test()
{
NSLog(@"学习OC第一天");
}

10. Compilation, connection and execution of OC programs.
1) Negotiate the source code that conforms to the OC grammar specification in the .m file
2) Use the compiler to compile the source code into an object file: cc -c xx.m
3) Link: cc main.o
If the program uses the functions and classes in the framework, then when connecting, you must tell the compiler
cd main.o -framework Foundation
4) After the connection is successful, an a.out executable file will be generated and executed.

Guess you like

Origin blog.csdn.net/yanwenyuan0304/article/details/124970881