IOS Nsarray Array filtering

Source: Internet
Author: User

        ios-filter elements within an array//inside the DataArray, the elements that are in DataArray and within the Filteredarray array are filtered out//the array of elements that need to be removed Nsmutablea        Rray *filteredarray = [[Nsmutablearray alloc]initwithobjects:@ "1", @ "3", @ "9", nil]; Array required to be filtered nsmutablearray *dataarray = [[Nsmutablearray alloc]initwithobjects:@ "1", @ "2", @ "3", @ "1", @ "1", @ "3", @ "1", @ "                        5 ", @" 7 ", nil];         /* Method One: Use Nspredicate Note: Nspredicate belongs to the cocoa Framework, in the password, user name and other regular judgments used.                Similar to the SQL statement not the self represents the string itself in the in range operator then the not (itself in%@) means: Not the value of the string specified here */        Nspredicate * filterpredicate = [nspredicate predicatewithformat:@ ' not ' (self in%@) ", Filteredarray];        Filter array Nsarray * Reslutfilteredarray = [DataArray filteredarrayusingpredicate:filterpredicate];                        NSLog (@ "Reslut Filtered Array =%@", Reslutfilteredarray);        /* Method Two: Iterate the array from backward, then match delete */int i = (int) [DataArray count]-1; for (; I >= 0;i--) {//containsobject Determines whether the element exists in the array (as determined by the memory address of the two: YES differs: NO) if ([Filteredarray containsobject:[dataa            Rray objectatindex:i]) {[DataArray removeobjectatindex:i]; }} NSLog (@ "Data Array =%@", DataArray);

IOS Nsarray Array filtering

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.