Deconstruct Hello objective-C program Reading Notes

Source: Internet
Author: User

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!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.