nspredicate

Core Data, NSPredicate and to-many key

I have a Core Data model in which a Task entity includes an optional to-many relationship excludedOccurrences. One of the properties of excludedOccurrences is start, which is an NSDate object. The ExcludedOccurrence entity has an inverse mandatory to-one relationship to the Task entity. In order to fetch tasks for a specified day, I nee...

Writing an NSPredicate that returns true if condition is not met

Hi, I currently have the following piece of code NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF contains '-'"]; [resultsArray filterUsingPredicate:pred]; This returns an array with the elements which contain '-'. I want to do the inverse of this so all elements not containing '-' are returned. Is this possible? I've tr...

The correct NSPredicate format for one-to-many relationship in Core Data

Hello, I have a managed object model A and B with one-to-many relationship. For this particular task, I want to retrieve all A objects which has a relation to B with a property matches to "string". I had tried @"ALL bObjects.bProperty MATCHES 'string'", and it caused an objc_exception_throw in: [NSSQLGenerator generateSQLStatementFor...

Performing lookup on multiple entities using NSPredicate

Hi, I've run into a problem when I've been porting my code over from a SQLite database to Core Data. The data that I'm using comes from a existing database and as such has all the relationships defined using the ID of each of the tables (or entities now that I'm using Core Data). My problem is that I want to query against a single tabl...

Editing an NSPredicate using NSPredicateEditor

I can create an NSPredicate easily using an NSPredicateEditor (a subclass of NSRuleEditor). What I'd like to know is this: How can I take an existing NSPredicate (one created by the editor) and reload it into the editor so that I can alter it? EDIT: I tried @John's suggestion of using setObjectValue:, but that didn't quite work. Let ...

NSPredicates and double to-n relationships

Hi! I have an Core Data entity called Album; an album has a relationship to Song entities (called songs), and each Song has an arbitrary count of Tag entities (in a tags property), tags have a name. Now I want to check whether any of the songs in an Album contain a Tag; using a single NSPredicate. An ideas that came to mind was: [NSP...

NSFetchedResultsController and constructing NSFetchRequests

I have setup Core Data for an iPhone app without an instance of NSFetchedResultsController. To do this, I created a created a model class to encapsulate all core data requests and constructing of NSFetchRequests/NSPredicates. This kept all Core Data specific code out of my UITableViewController. Now I want to add NSFetchedResultsContr...

NSMutableArray from filterUsingPredicate error

I am trying to return a subset of my NSMutableArray (MessageArray) with the following code. MessageArray contains an NSDictionary, one of the keys being FriendStatus. I get a strange error which I know is a DUH syntax issue. "error. void value not ignored as it ought to be". -(NSMutableArray*)FriendMessageArray { NSPredicate *pred...

iPhone - getting unique values from NSArray object

I have an NSArray formed with objects of a custom class. The class has 3 (city, state, zip) string properties. I would like to get all unique state values from the array. I did read through the NSPredicate class but couldn't make much of how to use it in this case. The only examples I could find were for string operations. Can someone ...

Core Data Query for iPhone

I am new to core data and before I was using sqlite. I found SQLite is not efficient and since my application is using extensive database communication, I have to compile the statements. With all this running my application breaks giving memory warnings, sometimes its views sometimes gets blank in between. Is it because of using SQLite...

CoreData fetch request through abstract managed object to concrete managed object

Hi all, I'm trying to execute a fetch request against a Managed Object Context with a predicate that tests against a keypath that exists in some subclasses of an abstract class. For example here is a part of the object model Library::NSManagedObject - AllMovies::to-many relationship->Movie Movie::NSManagedObject (abstract) - type:...

Deleting Duplicate Objects in Core Data (iphone)

In my iPhone app I provide users with a view of industry news items. I get this list as an xml file from my server. Parsing and inserting the xml data into my Core Data repository is a no brainer, but there are a few cases where I might get duplicate news item entries. I thought a good solution would be to insert all the updates when I ...

NSPredicate and simple Regular Expression problem

I'm having problems with simple NSPredicates and regular expressions: NSString *mystring = @"file://questions/123456789/desc-text-here"; NSString *regex = @"file://questions+"; NSPredicate *regextest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; BOOL isMatch = [regextest evaluateWithObject:mystring]; In the above exa...

CoreData: Find minimum of calculated property

Say I have a CoreData entity "Point" with two properties x and y (both NSNumber). How would a NSPredicate need to look like to let me find the closest Point to say a,b? for distance = sqrt((x-a)(x-a)+(y-b)(y-b)) While I could define a transient property that calculates a distance to a predefined point I can't see how I could programma...

NSPredicate Memory Issues

So I am trying to fix this really annoying bug. If I filter my array like the ideal version with NSPredicate, I will get EXC_BAD_ACCESS because it tries to call release on the object passed in as the delegate an extra time. If I filter with the working version, it works fine. I thought these two implementations were identical. Where am I...

Filter contacts in iphone address book

I've created an address book copy with ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook); CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy( kCFAllocatorDefault, CFArrayGetCount(people), people ...

hyphen in NSDictionary key

I've been working this for a few days now with no luck.. I am trying to parse a collection of key/value pairs from an NSDicitonary but it seems to be very sensitive to a hyphen in the key name. Below is an example of the data.. If I try to access any of the fields with a hyphen using the code below I get the following error: unreco...

Does re-fetching NSFetchedResultsController do anything?

I have a fetched results controller with a predicate on my Thing entity that looks like this: "thingDomain.domainCurrentAccount !=NULL". It finds all of my Thing objects that are in the current domain. The current domain is defined by a one-to-one relationship between the Account entity and one of the Domain entities. Each Thing belongs ...

How to write a Core Data predicate to filter to specific sub-entity types?

I have a superentity called FObject with several subentities, say Foo1, Foo2, and Foo3. I have a number of tableviews that should show information about different collections of the subentities, so for example, one shows only Foo2s and Foo3s while another shows all of them. How do I write a predicate to filter on the subentity type, giv...

Iphone NSPredicate how to do an INNER JOIN?

Hello, I have been looking thru the documentation and some other posts in this site, but I simply cannot understand how to work this out, which is actually very simple in SQL. Basically I have 2 entities Instruments and Deals. And the "Deals" use an "Instrument" to perform a desired operation. Now I want to list Deals attributes and t...