IOS development--nsmutablearray using enumeration methods

Source: Internet
Author: User

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

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.