• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [iPhone] Breaking content of NSMutable array into two arrays.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iPhone] Breaking content of NSMutable array into two arrays.


  • Subject: Re: [iPhone] Breaking content of NSMutable array into two arrays.
  • From: Wyatt Webb <email@hidden>
  • Date: Wed, 1 Sep 2010 08:35:24 -0700

On Sep 1, 2010, at 5:26 AM, Tharindu Madushanka wrote:

> Hi,
>
> I have a NSMutableArray that holds objects and they are sorted according to
> an integer value, either 1 (One constant), 2 (another constant).
>
> User {
> NSString *name;
> NSInteger state;
> }
>
> Now i want to split the content into two arrays. I saw this method..
>
> - (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)*predicate
>
> Could I use this method for my purpose, could someone give me an example
> usage of predicate or some other mean to do my task

I'm assuming that User is a real Objective-C class and not just a C struct.

If so, then you'd do something like this:

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"state = 1"];
NSArray* firstArray = [allObjects filteredArrayUsingPredicate:predicate];

predicate = [NSPredicate predicateWithFormat:@"state = 2"];
NSArray* secondArray = [allObjects filteredArrayUsingPredicate:predicate];

Wyatt
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [iPhone] Breaking content of NSMutable array into two arrays.
      • From: Tharindu Madushanka <email@hidden>
References: 
 >[iPhone] Breaking content of NSMutable array into two arrays. (From: Tharindu Madushanka <email@hidden>)

  • Prev by Date: Re: Dragging the window its goes to top of the screen.
  • Next by Date: Dealloc'ing a serial GCD dispatch queue?
  • Previous by thread: [iPhone] Breaking content of NSMutable array into two arrays.
  • Next by thread: Re: [iPhone] Breaking content of NSMutable array into two arrays.
  • Index(es):
    • Date
    • Thread