Objective-C Boolean Type & #160; and class, SEL type
It is found that many beginners cannot differentiate bool, BOOL, and class types. Today, I am free to write a blog post to differentiate them.
1. bool is a boolean type of C language, with true and false, BOOL is a boolean type of Objective C language, with YES and NO, because OC can be mixed with C, so bool and BOOL can appear in the code at the same time.
2. In-depth analysis of BOOL:
BOOL is actually a signed character type, and the storage space is 8 bits. Therefore, if a 32-bit integer is assigned to BOOL, only the last 8 bits will be taken.
In the BOOL type, "YES" is defined as 1, and "NO" is defined as 0. when data is stored in the internal storage, "YES" or "NO" is not saved. Therefore, if the last eight digits are zero after a value assignment, the Boolean value is NO.
3. SEL type
Corresponding to functions in OC
4. Class type
It is used to indicate a class name. After the class is created, we can regard the class as the class of the object.
For example:
[Class or object Class]; [Class or object superClass]; NSClassFromString (method name string );
Class class1 = [NSString class]; NSDictionary * a = [NSDictionary new]; Class class2 = [a class]; Class class3 = [a superclass]; class class4 = [NSDictionary superclass]; Class class5 = NSStringFromClass (@ "NSString ");