Variable groups can also use the enumeration method, we provide two kinds of enumeration methods here, one is a positive order enumeration, the reverse enumeration, in the positive order enumeration, the number of elements and order is not modifiable, but in reverse enumeration can be modified, which is somewhat intriguing.
The method involved:
Objectenumerator: A positive-order enumeration method.
Reverseobjectenumerator: Reverse Enumeration method.
Let's take a look at the examples below:
//A mutable array using the enumeration method#import<Foundation/Foundation.h>int main (int argc,Constchar * argv[]) {@autoreleasepool { Nsmutablearray *array = [[Nsmutablearray alloc]initwithobjects:@"One ",@"Tow ",@"Three ", Nil]; //Objectenumetator is a positive-order enumeration method. //The number of elements and the order of elements are not allowed to be modified when using the positive-order enumeration method.//Nsenumerator *enumerator = [array objectenumerator];//NSString *str;//int i = 0;//while (str = [Enumerator nextobject]) {//[Array Removelastobject];//NSLog (@ "%d", I);//}// //Reverseobjectenumerator is an enumeration method in reverse order. //In the inverse enumeration method, the number of elements and the order of elements are allowed to be modified. //PS: It is possible to use any offense to change the number of elements or order of elements in the reverse enumeration method. Nsenumerator *enumerator = [array reverseobjectenumerator]; NSString *str; while (str = [Enumerator nextobject]) { [array Removelastobject]; NSLog (@ " } // //2014-10-12 12:24:20.242 ENUMNSMUTABLEARRAY[881:303] () NSLog (@ "%@", array); [array release]; } return 0;
2014-10-13 on 20: 17:48.793 enumnsmutablearray [6403:303] three2014-10-13 20:17 :48.794 enumnsmutablearray [6403:303] tow2014-10-13 20:17 :48.794 enumnsmutablearray [6403:303] one2014-10-13 20:17 :48.795 enumnsmutablearray [6403:303] () program ended with exit code:0
IOS Development--nsmutablearray using enumeration methods