Concepts of classes and objects
A class is an abstraction of the same kind of thing, which defines the static attributes (attributes) and dynamic properties (methods) that such an object should have.
An object is an instance of a class and is a concrete thing.
Classes and objects are abstract and concrete relationships.
A class is actually a data type, and its variables are objects.
Relationship between class and class--inheritance relationship
A is B
If this is the case, in the design process can be regarded as an inheritance relationship.
For example: Students and primary school pupils are also students, so students are the parents of pupils, pupils are children of the class.
OC and Object-oriented
The object is the core of the OC program. "Everything is Object" is the core idea in the procedure.
A class is a template that is used to transcend objects of the same type, and defines the member variables and methods that the class object has in a class.
A class can be thought of as a collection of static attributes (instance variables) and dynamic properties (methods).
The IOS SDK provides a large number of classes for programmers to use, and programmers can define their own classes.
1,
Nil: null pointer to object in OC
Nil: null pointer to class in OC
NULL: Pointer to a different type of null pointer, such as a C-type memory pointer
NSNull: An object that represents a null value in a collection object
If obj is nil:
[obj message] will return no, not nsexception
If obj is nsnull:
[obj message] throws an exception nsexception
2,nil and Null are literally understood to be simpler, nil is an object, and null is a value, and my understanding of nil is to set the object to NULL, and NULL to set the base type to null. And we're not going to generate crash or throw exceptions for the nil call method.
Take a look at the usage
Nsurl *url = nil;
Class class = Nil;
int *pointerint = NULL;
Nil is an object pointer is empty, nil is a class pointer is empty, NULL is the basic data type is empty.
These five concepts are easy to confuse, and in some cases they have the same usage. First explain the meaning of the null pointer, which means that the pointer does not point to a meaningful memory area. such as int *p; int *p = NULL;
NSObject *obj1 = [[NSObject alloc] init];
NSObject *obj2 = [NSNull null];
nsobject *obj3 = [NSObject new];
NSObject *obj4;
Nsarray *arr1 = [Nsarray arraywithobjects:obj1, Obj2, Obj3, Obj4, nil];
NSLog (@"arr1 count:%ld", [arr1 Count]); //count:3 because Obj=nil, add objects when you join Obj4
NSObject *obj1;
NSObject *obj2 = [[NSObject alloc] init];
NSObject *obj3 = [NSNull null];
nsobject *obj4 = [NSObject new];
Nsarray *ARR2 = [Nsarray arraywithobjects:obj1, Obj2, Obj3, Obj4, nil];
NSLog (@"arr2 count:%ld", [arr2 Count]); //count:0, because Obj1=nil, so the object is not added in the following
[NSNull null] usually acts as a placeholder, as follows:
NSObject *obj1 = [NSNull null];
Nsarray *arr1 = [Nsarray arraywithobjects:@"One", @"One", obj1,@" Three ", nil];
for (NSString *str in arr1) {
NSLog (@"Array object:%@", str);
} //result:one, three, and
NSObject *obj1 = [NSNull null];
Nsarray *arr1 = [Nsarray arraywithobjects:@"One", @"One", obj1,@" Three ", nil];
for (NSString *str in arr1) {
if (str! = [NSNull null]) {
NSLog (@"Array object:%@", str);
}
}//result:one, three, and
The difference between nil/nil/null in iOS