• 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
filtering an array of entities using NSPredicate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

filtering an array of entities using NSPredicate


  • Subject: filtering an array of entities using NSPredicate
  • From: Koen van der Drift <email@hidden>
  • Date: Sat, 13 Oct 2012 17:23:42 -0400

I have a large array for Person entities, and want to filter them before importing into my Core Data database, so that each Person will be only once in the database based on the name.  The names are pulled from a database, and have the format: @"Jones, A."

After some searching, I came up with the following:

       NSFetchRequest  *fetchRequest = [[NSFetchRequest alloc] init];
        [fetchRequest setEntity: [NSEntityDescription entityForName: @"Person" inManagedObjectContext: context]];
        [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"name IN %@", persons]];

        NSError *error;
        NSArray *filteredPersons = [context executeFetchRequest: fetchRequest error: &error];

 // get the difference
	NSMutableArray *uniquePersons = [NSMutableArray arrayWithArray: persons];
	 [uniquePersons removeObjectsInArray: filteredPersons];

And then import them.


As it turns out, filteredPersons is always empty, even though I know certain names are already present

How can I make this work?

Thanks,

- Koen.
_______________________________________________

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: filtering an array of entities using NSPredicate
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: copy in WebView
  • Next by Date: IBOutlet & NSNumber
  • Previous by thread: Re: Long delay between viewWillAppear: and viewDidAppear:
  • Next by thread: Re: filtering an array of entities using NSPredicate
  • Index(es):
    • Date
    • Thread