Numeric value to boolean type,1. nsstring contains many features. For example, it can be directly converted to the numeric type (integer or floating point type)
1Nsstring * test =@"This is my name";
2 If (Nsorderedascending = [test compare: @" This is my name 2 " ]) {
3 Nslog ( @" Appreciation " );
4 }
5 Nsstring * floatvaluestring = @" 12 " ;
6
7Nslog (@"% D floatvalue is % F", [Test length], [floatvaluestring floatvalue]);
2. How to Use nslog to output bool-type values.
Bool isbool = yes;
Nslog (@"% @", Isbool = Yes?@"Yes":@"No");
3. You can assign an integer value to the bool type. The output result is"
Numeric value to boolean, 14"
Bool canacceptdigital =14;
Nslog (@"Numeric value to boolean, % d", Canacceptdigital );
4. In objective-C, Yes indicates 1, and no indicates 0.
1 If(2){
2 Nslog ( @" 2 can be executed " );
3 Nslog ( @" Yes is % d " , Yes );
4 Nslog ( @" No is % d " , No );
5}
The output is as follows:
21:12:04. 763 Lookbook [791: 207]2 can be executed
21:12:04. 773 Lookbook [791: 207]
Yes is 1 21:12:04. 778 Lookbook [791: 207]
No is 0
5. Use % @ in nslog to output the definition in the description function of the object.
Header file: person. h
1 # Import <Foundation/Foundation. h>
2
3
4 @ Interface Person: nsobject {
5
6 }
7 -(Nsstring *) description;
8 @ End
Implement file person. m
# Import "Person. h"
@ Implementation Person
-(Nsstring *) Description
{
Return @" My name is description " ;
}
@ End
Add the following method to viewdidload:
-( Void ) Viewdidload {
[Super viewdidload];
Person * D = [[person alloc] init];
Nslog (@"Person's description is % @", D );
}
The result is as follows:
Person's description is my name is description
The next chapter, basic knowledge of object-oriented programming, is to be continued. Coming soon!