Quick enumeration and array ordering in OBJECTIVE-C

Source: Internet
Author: User

Quick Enumeration

For (< #type *object#> in < #collection #>) {

}

object is a traversal of the resulting element object, collection is a collection-type object: An array, a dictionary, a collection.

An array enumeration gets the element objects in the array.

The dictionary enumeration gets the key value in the dictionary.

The collection enumeration gets the element objects in the collection.

1 //Array2Nsarray *arr = [Nsarray arraywithobjects:@"IPhone",@"Demaxiya",@"Emerald Dream",@"Valley of the Dragon",@"Bloodstrike", DIC, nil];3     //The array is quickly traversed to get each element4      for(NSString *tempincharr) {5NSLog (@"Temp%@", temp);6     }7 //Dictionary8Nsdictionary *dic = [Nsdictionary Dictionarywithobjectsandkeys:@"Zhangsan",@"name",@"male",@"Sex",@" -",@" Age", nil];9      for(NSString *tempinchdic) {TenNSLog (@"Temp%@", temp); OneNSLog (@"%@ = %@", temp, [dic objectforkey:temp]);  A}

Array sorting

Array default sort

Immutable groups: [Array sortedarrayusingselector:<# (SEL) #>].

1Nsarray *arr = [Nsarray arraywithobjects:@"1",@"4",@"2",@"3", nil];2NSLog (@"arr:%@", arr);3 //Sorting Methods4 //SEL Method Type5 //@seletor () method Selector6SEL method =@selector (compare:);7Nsarray *ARR1 =[arr Sortedarrayusingselector:method];8NSLog (@"arr%@", arr1);

Variable group: [Mutablearray sortusingselector:<# (SEL) #>].

1 //variable Array ordering2Nsmutablearray *marr =[Nsmutablearray Arraywitharray:arr];3NSLog (@"arr:%@", arr);4 [MARR sortusingselector: @selector (compare:)];5NSLog (@"arr:%@", MARR);6[MArr AddObject:@"app"];7[MArr AddObject:@"Store"];8 [MARR sortusingselector: @selector (compare:)];9NSLog (@"arr:%@", MARR);

Quick enumeration and array ordering in OBJECTIVE-C

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.