Objective-c (frame)

Source: Internet
Author: User

The framework refers to Objective-c's foundation library, which gives several common classes and their methods in the following example.

    • Numeric objects
NSNumber *Intnum; NSNumber*Longnum; NSNumber*Floatnum; Intnum= [NSNumber Numberwithinteger: A]; NSLog (@"%i", [Intnum IntegerValue]); Longnum= [NSNumber Numberwithlong:0x123456]; NSLog (@"%LX", [Longnum Longlongvalue]); Floatnum= [NSNumber numberwithfloat:12.00]; NSLog (@"%f", [Floatnum Floatvalue]); if([intnum isequaltonumber:floatnum] = =YES) {NSLog (@"Eqaul");//same}Else{NSLog (@"Not equal"); } 
    • String
NSString *STR1 =@"Hello,world"; NSString*STR2 = [NSString stringWithFormat:@"%i,%@",5,@"Fredric"]; NSLog (@"%@%@", STR1,STR2);                NSLog ([str1 stringbyappendingstring:str2]); Nsmutablestring*STR3 = [nsmutablestring stringwithstring:@"Hello"]; [Str3 appendString:@"Fredric_"]; [Str3 insertstring:@"Word"AtIndex:str3.length]; NSLog (@"%@", STR3);//Hellofredric_wordNsrange Res= [STR3 rangeofstring:@"Ric"]; if(Res.location! =nsnotfound)        {[Str3 deletecharactersinrange:res]; } NSLog (@"%@", STR3);//Hellofred_word
    • Array
Nsarray *array = [Nsarray arraywithobjects:@"Demo1",@"Demo2",@"Demo3", nil];  for(inti =0; i < [array count]; i++) {NSLog (@"%@", [array objectatindex:i]); } Nsmutablearray*marray = [Nsmutablearray arraywithcapacity:3]; [Marray AddObject:@"Demo4"]; [Marray AddObject:@"Demo5"]; [Marray AddObject:@"Demo6"];  for(inti =0; i < [Marray count]; i++) {NSLog (@"%@", [Marray objectatindex:i]); }
    • Dictionary
Nsdictionary *dic = [Nsdictionary Dictionarywithobjectsandkeys:@"value1",@"Key1",@"value2",@"Key2",@"VALU3",@"Key3", nil]; NSString*value1 = [dic objectforkey:@"Key1"]; NSLog (@"%@", value1); Nsmutabledictionary*mdic =[[Nsmutabledictionary alloc]init]; [MDic setobject:@"value1_1"Forkey:@"Key1"]; NSLog (@"%@", [MDic Objectforkey:@"Key1"]);

Objective-c (frame)

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.