Object-orientedCLanguage
When it comes to object-oriented languages, most Windows developers first think of C ++, C #, or Java. However, if you first think of objective-C, you should be a developer in Mac OS, in this modern computer system, mac OS X, an Apple company that uses objective-C at most.
Object-CAndC ++
Object-C is based on the C language and incorporates the object-oriented components of smalltalk, which is very different from most Java-based object-oriented languages.
In addition, unlike the memory structure of other object-oriented hidden classes, object-C uses C language to implement classes. That is to say, it is opposite to the modern object-oriented thinking mode, instead of re-introducing object-oriented elements in a language, we can use the design pattern to implement the object-oriented thinking without adding new elements in the C language. For example, the C ++ or Java language itself contains the class object-oriented concept. A more popular saying is that the class keyword is an integral part of the language, in object-C, the class definition should be put into the header file, which is essentially a constructor hidden by typedef. Therefore, object-C has a high affinity with C language, which makes Java developers very unacceptable. However, it is a good opportunity for developers who are familiar with C language and design patterns.
Object-CCompiling environment
If the system is Mac OS X, you can use objective-C immediately after installing the affiliated development environment. In Linux, GCC or GCC, which is specially used in windows, can also compile objective-C.
New preprocessing command
Objective-C is an extension of the C language and a subset of objective-C. Therefore, the C language can be run in the objective-C environment without any modification. More accurately, objective-C is not an extension of the C language itself, but an extension of the compiler. the compiler will eventually translate objective-C into the C language, and the compilation results of the twoCodeIt will be exactly the same. The new append keyword in objective-C is simply a redefinition of # define or typedef in the header file.
Therefore, to correctly run objective-C, you must first introduce a specific header file. The newly introduced keywords and types in objective-C are defined inObjc/objc. hIn this header file. But remember,Objc/objc. hThe function defined in is only supportedObjective-C: the minimum set for normal operation. This header file varies with the compiler. In the GCC compilerObjc/object. h, InMac OSOfCococaIsFoundation/nsobject. h. InObject-CThe header file of the non-dependent compiler is describedObjc/objc. h.
Reference header files inObject-CAdded# ImportThis preprocessing command.# ImportExcept that existing files are not repeatedly introduced.(Duplicate reference inCLanguage is a headache), Both usage and functions# IncludeSame.
# Import<Header file>
# Import "Header file"
If you still insist on using # include to introduce header files, do not forget to handle repeated references.
In addition, similar to the previous C language, to use standard functions such as printf (), you also need to reference the stdio. h header file. It also needs to be noted that the objective-C sourceProgramThe file extension is. m instead of. C.
# Import<Stdio. h>
# Import<Objc/object. h>
IntMain (){
Printf ("Hello world \ n");
Printf ("Hello wordl too \ n");
Return 0;
}
From the above program, we can see that objective-C is almost the same as C. In fact, objective-C is not similar to C, but completely interchangeable with C, or essentially C.
In addition to the C language/**/, objective-C adds a single-line comment method such.
Part II:Objective-CGetting started(2)Class description and definition