I want to retrieve the most recently added record from CoreData. I was wondering if that's possible using NSPredicate? If so, how?
e.g. i have a one-to-many relationship between Department and Staff, and i want to fetch the Staff record that was most recently employed. The Staff table has a date field which can be used.
I don't want t...
Building a search with some custom objects and three scopes: All, Active, and Former. Got it working with the below code:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString *)scope {
[[self filteredArtists] removeAllObjects];
for (HPArtist *artist in [self artistList]) {
if ([scope isEqualToString:@"...
I have a case where i have three entities with one-to-many and one-to-many relationships:
Entity A (Entity B relationhip),
Entity B (Entity A relationship, Entity C relationship),
Entity C (Entity B relationhip)
I have the reference of Entity A, and now i want to fetch all the related Entity C records. How can i do that? (with least ...
I'm trying to create an NSPredicate to find 'projects' that contain 'sessions' within a certain date range. I tried this at first:
[NSPredicate predicateWithFormat:@"ANY sessions.date BETWEEN {$STARTDATE, $ENDDATE}"];
But I get an exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'to-ma...
Hi,
Just wondering what the best way to build a NSPredicate is if some filters are optional?
This is basically for a filter, so if some options aren't selected I don't to filter by them
eg. If I have option1 and option2 set for the filter.
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"option1 = %@ AND option2 = %@] .......
I'm using a simple NSComparisonPredicate similar to: ("employeeDepartment != %@", department) where employeeDepartment is an optional, one-to-many relationship in Employees, and department is an NSManagedObject of Departments. When applied against the Employees entity, I'm getting different results from an NSArrayController vs an NSFetch...
Hi
On my Core Data Entity "Book" i have a boolean property, 'wasViewed' (NSNumber numberWithBool)
that tells me if the Book was "viewed".
I would like to implement a sort of "reset" this property for all my NSManagedObjects "Book". So that I can set them all to NO between sessions.
I use an NSPredicate to retrieve all the Books like th...
Hi !
I read this post but I don't really understand the code...
I have a core data database with an Entity and some attributes. One of them is named "myDate" and has for type NSDate.
Now I want to to display each date but eliminate dates with same day-month-year and display them ascendantly .
Have you got an idea?
Thanks a lot !
...
Is there any common way to decompose an expression created by [NSPredicate predicateWithFormat] to objects NSComprasionPredicate, NSExpression and other?
For below example need to disassemble into components.
[NSPredicate predicateWithFormat:@"(0 != SUBQUERY(collection, $x, $x.name == "Name").@Count)"];
...
I'm looking for a way to use NSPredicate to set a LIKE condition to fetch objects. In addition to that, an OR would be useful as well. I'm trying to do something where if a user searches "James" I can write an NSPredicate that will do the equivalent of:
select * from users where firstname LIKE '%James%' OR lastname LIKE '%James%';
...
I have a core data project that has Books and Authors. In the data model Authors has a to-many relationship to Books and Books has a 1-1 relationship with Authors. I'm trying to pull all Books that do not have an Author. No matter how I try it, no results are returned. In my predicate I've also tried = NIL, == nil, == NIL. Any suggestion...
I have an AUDIO class. This audio has a SOUND_A subclass and a SOUND_B subclass. This is all done correctly and is working fine.
I have another model, lets call it PLAYLIST_JOIN, and this can contain (in the real world) SOUND_A's and SOUND_B's, so we give it a relationship of AUDIO and PLAYLIST.
This all works in the app.
The proble...
Hi
I have an Array of NSDictionary objects.
These Dictionaries are parsed from a JSON file.
All value objects in the NSDictionary are of type NSString, one key is called "distanceInMeters".
I had planned on filtering these arrays using an NSPredicate, so I started out like this:
NSPredicate *predicate = [NSPredicate predicateWithForm...
Hi all,
I have a data model with a many-to-many relationship like EntityA <-->> EntityB <<--> EntityC. I used to query EntityA with different search criteria and I use NSCompoundPredicate with an array of NSPredicates. On one of the predicate I wanted to query EntityA using EntityC. I tried to use the following SUBQUERY but it did not w...
Working on an app where I have a large collections of managed objects against which I want to fetch a few random instances.
My question is, is there any way I can use NSPredicate and NSFetchRequest to return several objects at random.
I saw that you could actually add a NSFetchRequest into the entity using the data modeler, any way to ...
Using Core Data w/a sqlite store on iPhone.... I've got a bunch of comic book image entities, each with a string that includes the comic's issue#, e.g.: image.imageTitle = @"Issue 12: Special Edition";
Part of the UI allows the user to type in an issue number to jump to the next issue. My initial code for this was sloooooooow because im...
i have an NSObject with 2 property's
@interface Entity : NSObject {
NSNumber *nid;
NSString *title;
}
i have 2 array's with Entity's objects in it and I want to compare those two on the nid with a predicate
array1: ({nid=1,title="test"},{nid=2,title="test2"})
array2: ({nid=2,title="test2"},{nid=3,title="test3"})
the 2...
I'm having trouble compounding NSPredicate with AND, although using OR works fine.
Imagine 2 entities, Doctor and Patient. Doctors can have many patients and patients many doctors. I want to find doctors that, say, have both person1 and person2 as patients. I expected this to work but it returns none.
NSPredicate *predicate = [NSPre...
I'm using Core Data to store a lot (1000s) of items. A pair of properties on each item are used to determine uniqueness, so when a new item comes in, I compare it against the existing items before inserting it. Since the incoming data is in the form of an RSS feed, there are often many duplicates, and the cost of the uniquing step is O(N...
I have a NSArray of CalEvents returned with the [CalCalendarStore eventPredicateWithStartDate] method. From the events returned, I am trying to keep only those in which the title of the event == @"on call" (case-insensitive).
I am able to keep in the array those events whose title includes @"on call" with the following code (where event...