1,oc language of past life,
First, in the early the 1980s, Brad Cox designed the OC language, which added a layer to the C language, which meant that C was extended to create a new programming language that supported object creation and manipulation.
Second, in 1985, amid, who was driven out of Apple, set up the next company;
Third, in 1988, Next computer acquired the OC language authorization, and developed the OC Language Library and a development environment,
In 1994, Next computer company (renamed Next software company of the same year) and Sun company jointly issued a standard specification for the NeXTSTEP system, named OpenStep.
In 1996, Apple announced the acquisition of next software and turned the NEXTSTEP/OPENSTEP environment into the foundation of OS X, the next major release of Apple's operating system, a development environment that was known by Apple as Cocoa, and was widely recognised by Mac developers. In addition, since cocoa has built-in support for the OC language, OC has become the preferred development language for Mac OS x platforms over time. Until later, the iOS system was released, and OC was also its preferred development language. Improve the status of OC in the development language;
2,oc language Introduction,
One, the difference between import and include;import prevents duplicate inclusion of header files
Second, the difference between NSLog and printf:
1,nslog can automatically wrap, output debugging information, printf cannot.
The argument to the 2,nslog function is a NSString object
The argument to the 3,PRINTF function is a string constant pointer
Three, the meaning of the @ symbol:
1,@ "" Converts a C string of double quotation marks to an OC string Object nstring;
A unique identifier in the 2,OC, preceded by a lot of keywords plus @.
Four, OC can access functions in the C source file. C cannot azimuth the method in the source file in OC. (This is actually backwards compatible)
The difference between 3,oc language and C,
One, source file comparison
The common source files in 1,c are. C and. h;
The common source files in 2,oc are. h and. m;
Second, the basic grammatical comparison
1. Data type comparison:
First OC compatible with all data types in C, C cannot be compatible with OC data type
OC New data types: Boolen, block, nil, class, SEL, etc.;
2, Flow control statement comparison;
First, OC is compatible with all Process control statements in C;
OC has added its own for in-enhanced loop statement;
For (NSString *str in arr) {
NSLog (@ "%@", str);
}
3, the comparison of function and method definition declaration;
Declaration and implementation of functions in C language
function declaration:
int sum (int a,int b);
function implementation
int sum (int a,int b) {
return a+b;
}
Declaration and implementation of OC methods
Method declaration:
-(int) sum: (int) A and: (int) b;
Method implementation
-(int) sum: (int) A and: (int) b{
return a+b;
}
4. Exception Capture method
@try {
There's a code that could be wrong here.
int result = A/b;
}
@catch (NSException *exception) {
NSLog (@ "exception =%@", exception);
}
@finally {
No matter what happens, the code here is bound to execute
printf ("fengjie!\n");
}
4, object-oriented,
First, object-oriented programming (oriented Programming-oop) is a design and programming method to solve software reuse. This method applies the similar operation logic and operation in the software system to the application of data and state, describes it in the form of the class, and reuse it in the software system by the object instance, in order to improve the efficiency of software development.
Object-oriented is process-oriented.
The inner part of the object is actually a process. It just encapsulates these processes.
Let's do one thing:
If it's a process-oriented mindset:
Generally is to find a way;
If it is object-oriented thinking:
The general is to find the object;
5, the abstract relationship of classes and objects,
One, what is a class?
In layman's words, an upward abstraction of an entity with the same attributes and behavior.
For example: The man, the woman, the upward abstraction as a class, that is, human;
The dogs, cats, tigers and other animals are abstracted upward into a category, that is, the class of animals; animal class;
Two, what is an object?
Refers to a variety of entities in the real world. It can refer to a specific thing or an abstract thing.
For short, everything is Object
Third, the abstract relationship of classes and objects:
Classes and objects do not open at the time;
Each object must have its own class;
Each class must have its own corresponding instance (object);
Classes are abstracted from objects;
The object is a concrete instance of the class (new);
6, the code of the class is created,
First, the creation of classes in OC is divided into two steps:
1, Declaration of class:
@interface Car:nsobject
{
Properties of the class
int Lunzi;
NSString *color;
int speed;
}
Method declaration
@end
2, the implementation of the class:
@implementation Car
Method implementation
@end
7, the members of the class are composed and accessed
First, what are the members of the class?
Member variables (properties)
Member method (behavior)
Second, access member variables:
Premise: member variables need to be decorated with @public modifier;
Car *car1=[car New]; Class Name: Car object Name: car1
Car1->lunzi = 3; Access by using;
Third, access method:
Car *car = [car new];
[Car Run]; Use [] to access the method;
Access to class methods: [Car stop]//[class name plus method name];
Four, the definition of OC method;
A method that has a parameter
-(return value type) method Name 1: (parameter type) parameter name;
-(void) NUM1: (int) one; Method Name: Num1: Parameter type: int parameter name: one
Methods with 2 parameters
-(return value type) method Name 1: (parameter type 1) Parameter name 1 Method Name 2: (parameter type 2) parameter name
-(int) NUM1: (int) One andtwonum: (int.) Method Name: Num1:andtwonum: Parameter type: int int parameter name: one Two
1,oc language of the past life, 2,oc language introduction, 3,OC language and C differences, 4, object-oriented, 5, class and object abstract relationship, 6, Class code creation, 7, class membership and access