Object-C, NumberDemo, and StringDemo

Source: Internet
Author: User

Object-C, NumberDemo, and StringDemo
Two demos were written at night.
The first is a demo string, and the second is a demo array and a variable array.
Only a few basic methods and basic statements are used.


NSString String object, NSNumber, NSMutableNumber, if statement, and NSLog method.


Using Mac to learn Object-C is really hard.
The programming syntax is very simple, that is, the Mac keyboard buttons, shortcuts, and mouse scrolling, which does not match Windows and HP computers.


In addition, the biggest pitfall of Object-C is method calling. [a add B] uses brackets to indicate method calling, which is amazing enough.
Your uncle's ~ Wipe ~


/// Main. m // StringDemo /// Created by fansunion on 15/11/16. // Copyright (c) 2015 demo. All rights reserved. // # import
 
  
Int main (int argc, const char * argv []) {@ autoreleasepool {NSString * str1 = @ FansUnion; NSString * str2 = @ XiaoLei; NSString * str3 = @ XiaoLei; // calculate the length of the string NSLog (@ str1 length % lu, [str1 length]); // verify that the two strings are equal if ([str1 is1_tostring: str2]) {NSLog (@ str1 = str2);} else {NSLog (@ str1! = Str2);} if ([str2 isw.tostring: str3]) {NSLog (@ str2 = str3);} else {NSLog (@ str2! = Str3) ;}} return 0 ;}
 


21:08:20. 723 StringDemo [2139: 127831] str1 length 9
21:08:20. 724 StringDemo [2139: 127831] str1! = Str2
21:08:20. 724 StringDemo [2139: 127831] str2 = str3
Program ended with exit code: 0


/// Main. m // NumberDemo /// Created by fansunion on 15/11/16. // Copyright (c) 2015 demo. All rights reserved. // # import
 
  
Int main (int argc, const char * argv []) {@ autoreleasepool {// unchangeable array NSArray * names = [NSArray arrayWithObjects: @ FansUnion, @ XiaoLei, nil]; NSLog (@ NSArray !); Int I = 0; for (I = 0; I <2; I ++) {NSLog (% @, [names objectAtIndex: I]);} // variable array NSMutableArray * numbers = [NSMutableArray array]; NSNumber * myNumber; for (I = 0; I <10; I ++) {myNumber = [NSNumber numberWithInteger: i]; [numbers addObject: myNumber];} // display the value in the array for (I = 0; I <10; I ++) {NSLog (@ % @, [numbers objectAtIndex: I]) ;}} return 0 ;}
 


21:22:04. 533 NumberDemo [2218: 131384] NSArray!
21:22:04. 534 NumberDemo [2218: 131384] FansUnion
21:22:04. 535 NumberDemo [2218: 131384] XiaoLei
21:22:04. 535 NumberDemo [2218: 131384] 0
21:22:04. 535 NumberDemo [2218: 131384] 1
21:22:04. 535 NumberDemo [2218: 131384] 2
21:22:04. 535 NumberDemo [2218: 131384] 3
21:22:04. 536 NumberDemo [2218: 131384] 4
21:22:04. 536 NumberDemo [2218: 131384] 5
21:22:04. 536 NumberDemo [2218: 131384] 6
21:22:04. 536 NumberDemo [2218: 131384] 7
21:22:04. 536 NumberDemo [2218: 131384] 8
21:22:04. 536 NumberDemo [2218: 131384] 9
Program ended with exit code: 0



 

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.