Questions tagged [nspredicate]

The NSPredicate class is used in Mac OS X and iOS development to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.

The NSPredicate class is used in Mac OS X and iOS development to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.

An example predicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(lastName like[cd] %@) AND (birthday > %@)", lastNameSearchString, birthdaySearchDate];

Multiple predicates can be combined into a more complex predicate with NSCompoundPredicate.

Full reference available in Apple's docs for NSPredicate. Also refer to the Predicate Programming Guide.

2953 questions
1
vote
1 answer

NSPredicate filter array but return only one field of an object

I'm sure this question has been asked but I don't know what to search on. I have array of Message objects with the following fields {selected[BOOL], messageText[STR]}. I want to filter this array to get only the objects with selected=TRUE. So far so…
Kirby Todd
  • 11,254
  • 3
  • 32
  • 60
1
vote
1 answer

NSPredicate over different entities

I want to make NSPredicate over different entities. Here is my core database. To make it simple, this is the query I should do. Select c.c_name From Company c, Person p Where c.c_id = p.cu_company_id Now I was wondering how my predicate should…
Steaphann
  • 2,797
  • 6
  • 50
  • 109
1
vote
3 answers

NSPredicate search for number in NSString

I have to find number in NSString using NSPredicate. I am using following code. NSString *test = @"[0-9]"; NSString *testString = @"ab9"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%@ CONTAINS[c] %@)", test,testString]; BOOL…
Nik
  • 682
  • 1
  • 8
  • 27
1
vote
1 answer

How to define a NSPredicate which specifies a having max(x) clause using group by?

I am having trouble creating a valid NSPredicate within an iOS-CoreData context. The table contains all messages of all buddies. I need to get the newest message of each buddy: I have tried using DBVisualizer and I need the following SQL (which…
theguy
  • 1,232
  • 1
  • 9
  • 21
1
vote
0 answers

Application error: Can't do regex matching on object

I parse XML and I have search bar. When I try search, I get this error: Can't do regex matching on object . I think problem is here: - (void) searchTableView { [filteredList superclass]; filteredList = nil; …
Alien
  • 29
  • 7
1
vote
1 answer

nspredicate for searching entity relationships

I wrote the following predicate for the following structure, not sure if its working correctly: I have a Car.h managedobject Car.h - name, make, model. toCarParts relationship - CarPart.h - wheel, …
William Falcon
  • 9,813
  • 14
  • 67
  • 110
1
vote
2 answers

Searching into an array of NSManagedObjects

Suppose I have already retrieved an array of managed objects (an array of Car objects). Lets say a Car has attributes like make and model. Cars are currently in an NSArray. How can I find all cars with honda value for make attribute?
William Falcon
  • 9,813
  • 14
  • 67
  • 110
1
vote
1 answer

CoreData fetch request - complex predicate

How would I simplify this using (ideally) a single predicate with key-value coding collection operators? (The array of interest in the end is filteredGames.) NSManagedObjectContext *context; NSFetchRequest *request = [[NSFetchRequest alloc]…
1
vote
2 answers

NSPredicate of NSArray in NSDictionary

My Array ( {id:1,data:(@"macbook",@"mac mini")}, {id:2,data:(@"ipad",@"ipod")}, {id:3,data:(@"macbook",@"ipod")} ) I have a predicate NSString *text = @"mac"; [NSPredicate predicateWithFormat:@"(data contains[cd] %@)",text]; [array…
Andy Jacobs
  • 15,187
  • 13
  • 60
  • 91
1
vote
3 answers

NSPredicate using OR error

First time building an NSPredicate. I would like to search a managedobjectcontext using this logic: Search for a, grab all matches Search for b, grab all matches, etc.... Nsarray *results = (has all a results, b results, etc); My attempted…
William Falcon
  • 9,813
  • 14
  • 67
  • 110
1
vote
1 answer

Objective-c NSPredicate - Filter by ObjectId across different NSManagedObjectContext

I'm using the code below with my NSFetchedResultController NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.objRelationship.ObjectId == %@", objectFromOtherContext.ObjectId]; [fetchRequest setPredicate:predicate]; The…
1
vote
2 answers

iOS: FilterUsingPredicate on custom objects

I have a custom class extending NSObject. I am maintaining NSMutableArray of this class objects. Here is the situation, customObject-class { NSString *name; int ID; .....and many other properties; } customObjectsArray [ customObject1, …
Paresh Masani
  • 7,474
  • 12
  • 73
  • 139
1
vote
2 answers

NSPredicate check all items in array

I have an array of instances of my object - MyObject. Each instance has a string and an array property - myArrayProperty which contains instances of another class - MyOtherObject I am using an NSPredicate to do some filtering based on the values in…
John Lane
  • 1,112
  • 1
  • 14
  • 32
1
vote
1 answer

CoreData: NSPredicate based on relationships

I'm working on a recipe book right now using Core Data. It's the first time I'm using CoreData and it's working so far, but I'm having some trouble using it in the iPad's split view. Here's my object…
Naosuu
  • 13
  • 3
1
vote
2 answers

objective c nspredicates with OR's unable to parse

Anyone know why this gives an "Unable to parse the format string" error at runtime? [wordListArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"pinyin contains[cd] %@ OR pinyin contains[cd] %@ OR BEGINSWITH[cd] %@", [NSString…
ngb
  • 821
  • 9
  • 21