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
2 answers

NSPredicate possibly matching multiple properties

I have a Car class with instance variables such as "color" and "make". I need a NSPredicate that allows me to search for either color or make or both. NSPredicate*predicate=[NSPredicate predicateWithFormat:@"(color contains[c] %@) AND (make…
Tom Tallak Solbu
  • 559
  • 6
  • 20
1
vote
1 answer

NSPredicate regex not working

I'm using: + (BOOL)isPassword:(NSString*)password { NSString* pattern = @"^(?=.{6,20}$).*$"; NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern]; return [predicate evaluateWithObject:password]; } But…
lolol
  • 4,287
  • 3
  • 35
  • 54
1
vote
2 answers

Navigating the Core Data Object Graph [2]

I asked a question yesterday where I really should have started with a simpler example. Having distilled my question to the basics, I've managed to solve my problem using existing SO questions and answers. I'm summarising my question here (and…
user524261
  • 488
  • 1
  • 5
  • 14
1
vote
2 answers

NSPredicate working for more than, but not less than

I'm having a problem fetching results from a Core Data store using predicates. What my application does is fetches results from the store based on one or more predicates and shows you either the results based on all of the predicates or the results…
John Rogers
  • 2,192
  • 19
  • 29
1
vote
2 answers

NSPredicate and CoreData?

The query works fine if directly added to a predicate NSPredicate *predicate = [NSPredicate predicateWithFormat:@"author == %@", author]; [request setPredicate:predicate]; [self.managedObjectContext executeFetchRequest:request error:nil]; The query…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
1
vote
3 answers

NSPredicate to fetch all objects in a to many relationship

I have a User entity and an Email entity. A user has many emails. If I have a User object, I can access the set of emails with [user emails]. But how can I use an NSPredicate to retrieve all emails for a user? Assume there is no inverse…
Phil Loden
  • 1,394
  • 1
  • 15
  • 15
1
vote
2 answers

key example for item in nsdictionary array objective c

I have an array of dictionaries containing some values and keys.suppose keys k1,k2,k3,k4 etc... from this array I need to find object for key k1 for which I know the object of key k3 of the same dictionary. Is there any method without using…
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
1
vote
1 answer

How do I set up an NSPredicate to check a relationship's attribute?

I have an entity called Entry, which has a one-to-many relationship with an entity called Media. The relationship name, from the Media side, is entry. Entry has an attribute named entryID, and I want to create a NSPredicate on media entities which…
Andrew
  • 15,935
  • 28
  • 121
  • 203
1
vote
2 answers

Multiple Search Parameter in NSPradicate

I want to search my eventList Array based on multiple parameters like title,enddate etc... I am using follwing code when i use only one parameter titile like[cd] %@ it works perfectly NSCharacterSet *whitespace = [NSCharacterSet…
Anand
  • 1,129
  • 7
  • 29
1
vote
1 answer

NSPredicate for one-to-many relationship

Assuming a Department entity and an Employee entity with a one-many relationship Assuming relationship called employees on Department and department on Employee Assuming Employee has an attribute name I need to fetch all Departments that don't…
nick
  • 47
  • 1
  • 5
1
vote
2 answers

iOS app freezes, but doesn't crash?

So my app freezes and won't response to touch events. It doesn't crash it just sits there? If I push the pause button ||, it stops on the following line of code. NSArray *results = [context executeFetchRequest:request error:&error]; If I then push…
jdog
  • 10,351
  • 29
  • 90
  • 165
1
vote
1 answer

iOS: How do I add/remove a NSPredicate to my FetchedResultsController from a button press?

I have a button that I currently have set up as a toggle. It currently only changes it's text when pressed. I am wanting to have it filter out entries in my uitableview though. I'm guessing I'd do that by adding a NSPredicate to my…
daveomcd
  • 6,367
  • 14
  • 83
  • 137
1
vote
1 answer

Cocoa bindings + filter predicate + Auto Rearrange Content = crash

I'm encountering a problem where some simple Cocoa bindings are altering a fetch predicate attached to an ArrayController that has Auto Rearrange Content set. My data model has three classes (we'll call them A, B, and C). It's arranged in a strict…
1
vote
0 answers

NSPredicate - How to check if every parent has visible == true

my coredata structure contains "folder"s. Every folder can have a parent folder which can have a parent folder which can have a parent folder and so on. Folder can also have entities called "item". Folder has also property called "visible". I want…
mikkokut
  • 382
  • 1
  • 12
1
vote
1 answer

NSPredicate on nested object / NSSet to filter the result during NSFetchRequest

I want a simple predicate that returns me all the groups which have mode = 0 and the mode of the enrollments in the group = 0 To be precise i need a predicate to access the nested object properties. Somehow a predicate like: [NSPredicate…
yunas
  • 4,143
  • 1
  • 32
  • 38
1 2 3
99
100