C language is a process-oriented programming language, while OC is an object-oriented programming language. Object-oriented: For example, you do a dish, let the wife cook a dish, eat, this is the object-oriented, high efficiency oriented process, is every detail: for example, you have to take or open to the appropriate position. And then to wash vegetables, and so oil heat, to start cooking, and then seasoning,..., pot, into the bowl, eat .... Object-oriented programming code is easier to maintain. It encapsulates specific operational details in the class, using the time to create an object, a call method, done! (Of course, the implementation of the class still needs to write itself, object-oriented is only a programming idea.) OC inheritance, or expansion in the C language, OC can directly write C language code, which is OC backwards compatible.
oc in C language header file introduction in different ways:OC #import, the "objective-c" OC Project header file was selected when the OC project was created after the C language #include在Xcode老版本创建OC项目时候选择的是 the new version of the "Foundation" project: #importFoundat Ion contains a lot of OC library file references why use Improt? Both include and import are introduced header files Import header file Prevents duplicate include he uses preprocessing directives to prevent duplicate inclusions, and if there are no write preprocessing directives, it is not possible to prevent duplicate containment issues. The source file extension for OC is:. The source file name extension for the MC language is:. C header files are the data types of the. h file OC: C versus OC Keywords: many of OC's keywords come with the "@" Sign!
OC extends A For loop usage over the C language:No new process control is added to OC, OC provides an enhanced for loop:
1 #import<Foundation/Foundation.h>2 intMain (intargcConstARGV *Char[]){3 @autoreleasepool {4 5Nsarray *arr = @[@" One",@" Both",@"three"];6 //Enhanced for-loop7 for(NSString *strincharr) {8 9NSLog (@"%@ "", str);Ten One } A } - return 0; - }
Running Result: one
Both
Three
The prefix "NS" in OC is the first letter combination of Next and sunC printout function: printf ("") OC Printing output function: NSLog (@ "") NSLog (@ "") function can be wrapped, printf ("") function Yuyao input slash +n to break the line
I'm a black horse-----OC differs from C language