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