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 search for join table with nil values

I'm running a predicate search on a table called Todolists. Todolists have todos. I'm attempting to get all Todolists where the due_at (Date) is <= a certain Date or where the due_at Date is nil. The following predicate works fine, and gets all…
Brian Weinreich
  • 7,692
  • 8
  • 35
  • 59
1
vote
2 answers

Core data search through 2 relationships

I have 3 entities: Person, Region, and Boundary. Boundary has an attribute of 'state'. A person can have many regions. A region can have many boundaries: Person <<-->> Region <<-->> Boundary.state With a Person entity, I would like to find out all…
Padin215
  • 7,444
  • 13
  • 65
  • 103
1
vote
1 answer

Filtering an NSArray with NSPredicate

I have an NSArray that I would like to filter with a predicate. Here is what I have. NSLog(@"text is %@",txtSearch.text); NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] '%@'",txtSearch.text]; arrSearchedPlayers…
Steaphann
  • 2,797
  • 6
  • 50
  • 109
1
vote
1 answer

NSPredicate Query (KVC) on Collections Containing Collections

Edit (I missed a layer of detail): each teacher has an array of classes. (I ran the JSON through a validator, too, so it's a little easier to read) Assume the following JSON: { "schools": [ { "schoolID": "01", "schoolName":…
Gregory Hill
  • 155
  • 1
  • 14
1
vote
1 answer

NSPredicate comparing transformed CLPlacemark with another CLPlacemark

I'm saving CLPlacemark in Core data using NSValueTransformer. (so it's saved as NSData) However I've come to a point where I need to filter the saved objects based on another CLPlacemark object. I've tried this, it doesn't work: NSExpression…
Devfly
  • 2,495
  • 5
  • 38
  • 56
1
vote
1 answer

Filtering File Paths Using NSPredicate

I'm trying to filter an array of file paths of the format [number]_[number].png and get only the ones starting with a specific number, say 1. This is what I tried: NSPredicate *predicate = [NSPredicate predicateWithFormat: …
Ata01
  • 303
  • 4
  • 19
1
vote
2 answers

Searching CoreData relationships

I'm about to pull my hair out trying to figure out why this isn't working. I have two entities: Quote Customer A Quote has a one-to-one relationship property with a Customer called simply 'customer'. The Customer has a CoreData objectID…
random
  • 8,568
  • 12
  • 50
  • 85
1
vote
3 answers

How to filter array using NSPredicate such that value of one property is greater than other?

I have an array of objects which two properties X and Y (both NSString). I want to filter the array using predicate such that all the filtered objects have X > Y. Currently, I am using: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(X…
Deep Arora
  • 1,900
  • 2
  • 24
  • 40
1
vote
1 answer

How to filter SQL results by nspredicate date?

I am trying to filter sql lite database results by date but I am awful at ios date and time objects and not really sure how to do that. How would you set the NSPredicate to filter result by today, last 7 days, last 30 days and last 90 days? Thanks
user2067051
  • 99
  • 2
  • 15
1
vote
1 answer

Inefficient CoreData IN Query

I've got what should be a pretty simple CoreData setup that looks like this: Track { NSSet *artists; NSSet *genres; } Artist { NSSet *tracks; } Genre { NSSet *tracks; } So the idea here is, a Track can have multiple Genres and…
Tim
  • 4,560
  • 2
  • 40
  • 64
1
vote
1 answer

NSPredicate created with format and va_list/NSArray failed but string success

I created categories of NSManagedObject such as create, count and else. All of them works find except for following @interface NSManagedObject(ManagedObjectExtension) + (id)findWithPredicate:(id)stringOrPredicate, ...; @end @implementation…
Tar_Tw45
  • 3,122
  • 6
  • 35
  • 58
1
vote
1 answer

searching for a keyword in db in my iphone App

I want to know how can i implement keyword searching in my app. Actually i want to enter a text (in uitextfield ), then search my sqlite db and find out corresponding text in db.Iam a new bee to iPhone development, waiting for your help. Remember,…
Mumthezir VP
  • 6,251
  • 6
  • 28
  • 57
1
vote
1 answer

NSPredicate to filter nested CoreData Models

I'm having a CoreData models like bellow: Country <---->>> City (One-to-many relationship) Listed into a UITableView as section/row structure i.e. ===Egypt=== Cairo Alexandria Luxur Ras AlBar . . ===Qatar=== Doha . . . Now I have UISearchBar that…
Shady Elyaski
  • 499
  • 6
  • 15
1
vote
1 answer

Core Data - Find out if a relationship between two objects exists

I'm making an app with a questionnaire in it and I'm using Core Data to hold all of its data. There are three entities: Person (the person taking taking the questionnaire), Question (the question), QuestionResult (The result for a question) Person…
Mark Bridges
  • 8,228
  • 4
  • 50
  • 65
1
vote
2 answers

IOS: Merging two NSArrays while updating properties of "duplicates"

EDIT: Huge edit, sorry for causing confusion! I'm currently working on an app wherein I get 2 arrays from a JSON WebService using two different methods. In the first array, I get the local stock. In the second array I get the supplier stock. Though…
blaa
  • 438
  • 5
  • 19