nspredicate

NSPredicate syntax to exclude a given NSManagedObject

Hello all. I have a Core Data store in which many of the entities should be unique instances of their particular NSEntityDescription. I'm currently doing this by creating a new entity for a given description, then this: -(void)clearMyManagedObjectsExceptFor:(NSManagedObject*)except { NSArray *managedObjects = [ self fetchMyManagedO...

Dealloc'd Predicate crashing iPhone App!

To preface, this is a follow up to an inquiry made a few days ago: http://stackoverflow.com/questions/2981803/iphone-app-crashes-when-merging-managed-object-contexts Short Version: EXC_BAD_ACCESS is crashing my app, and zombie-mode revealed the culprit to be my predicate embedded within the fetch request embedded in my Fetched Results C...

How to search an NSSet or NSArray for an object which has an specific value for an specific property?

How to search an NSSet or NSArray for an object which has an specific value for an specific property? Example: I have an NSSet with 20 objects, and every object has an type property. I want to get the first object which has [theObject.type isEqualToString:@"standard"]. I remember that it was possible to use predicates somehow for this ...

Why does the LIKE[c] in my subquery predicate not match this name?

I have two entities: Department and DepartmentInfo. Every Department has one or many DepartmentInfo Objects. Inside DepartmentInfo, there is an departmentName attribute. I want to fetch all those Department objects which have a specific departmentName. So I make an NSFetchRequest for the Department entity, and use this fetch request: N...

How to prevent "SQL Injection" in Core Data?

I am building a pretty complex predicate in several iterations, and want to supply the matching values right away in the predicate. Instead of: [NSPredicate predicateWithFormat:@"departmentName like[c] %@"]; I want to do: NSString *str = [NSString stringWithFormat:@"departmentName like[c] '%@'", departmentName]; [NSPredicate predica...

How to dynamically build up the arguments for NSLog?

Example: I have a complex method that does a lot of stuff, and at the end I want to print a report with NSLog. NSLog wants a string, and then an arbitrary number of arguments. So lets say there are these possible values which can be logged: A B C D E F It can happen that -for example- C and D are not logged, but the whole rest. Ho...

Use NSPredicate for matching id's in two arrays

Hello i have a maybe easy question but i cant handle it yet. I have a Modelclass 'Location' which holds an Array with Category ID's (12, 23, 56). Then i have an Array with all available Category ID's (1,2,3,4,5,6,7,...) All this Categories have an ID are shown in a TableView and are able to select or not. I show a punch of Markers on a...

Why doesn't this NSPredicate work?

I have a very simple NSPredicate as such: NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"name beginswith '%@'", theString]; [matchingTags filterUsingPredicate:sPredicate]; This causes the array to have 0 results when theString == "p" However, when I do this: NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"...

NSPredicate help

NSPredicate *pred = [NSPredicate predicateWithFormat:@"firstname contains[cd] %@" argumentArray:firstNames]; NSArray *ar = [contactList filteredArrayUsingPredicate:pred]; What I want is to filter the contact list matching the values in the firstNames array. But this always results one element even if there are multiple matches? ...

NSPredicate issue

Hello everyone, I have 2 tables, 1 table is called table car and 2nd is called history. A car can have many histories so basically a history will have a foreign key carid which represents the car id. I am trying to extract all the history that is associated with the car but unfortunately, it keeps returning me every single history. ...

CoreData: returning a set of entities in a single fetch that match an array of nsnumber indexes

So I want to fetch a varying number of entities that match randomly generated index numbers that are associated to the entity. So i get a count of entities in a given set and i generate a random collection of nsnumbers within that range. now i need to pull out the entities whose index match those generated numbers ideally in a single fe...

Regex for an email address doesn't work

Hi, I'm trying to check if some email address is correct with the following code : NSPredicate *regexMail = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*@.*\..*'"]; if([regexMail evaluateWithObject:someMail]) ... But the "\." doesn't seem to work since the mail "smith@company" is accepted. Besides, I have the following warning...

Using selectors with NSPredicate

I have an object which contains several different NSStrings. When displaying this object, depending on another attribute of the object, I will display one string or another. I have a function defined in the object that takes care of deciding which string to display. So, as a simple example: @interface MyObject : NSObject { NSString*...

iphone core data save not working

Im trying to save a list of Device classes (a custom class) using Core Data and retrieve it. But After I save it, my query, which is VERY simple, doesnt return any records. My call to save the records always returns YES and no errors: BOOL resultOfSave = [managedObjectContext save:&err]; My predicate for searching by the property use...

NSFetchRequest predicate syntax

Hi, I have an entity called Task in my Core Data model. The Task entity has a transformable attribute called date. The class of the date attribute is a class called TDate (which conforms to NSCoding, therefore being a transformable attribute). TDate has a property of type NSInteger called month. In my NSFetchRequest I want to get all ...

NSPredicate to filter array of words to array of letters

I am trying to make "weighted" list of letters as words are created. I have a massive list of words in an NSArray. For example I am trying to acquire a new NSArray filled with just the 3rd letters of all the words based off the first two letters entered. So far I have... NSArray *filteredArray; if (currentWordSize == 0) { filteredA...

NSPredicate: Search on NSNumber (Cocoa)

Hi all, I have an Cocoa Core-Date Application. I added a search field and bound it. Now, I have tried to add some predicates but failed! Here are my two questions: First, the predicate should filter NSNumbers but I cannot build a working predicate. My try: keyPath == [NSNumber numberWithInteger:[$value integerValue]] (keyPath repre...

Why doesn't this NSPredicate work?

Hey, I have an Array of MKAnnotation objects called arrAnnotations. I want to pick out one of the annotations with the same coordinate as the one stored in a CLLocation object called "newLocation". I'm trying to use an NSPredicate, but it doesn't work. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF.coordinate == %f)...

Help w/ array of dictionaries in a tableview

This is kinda confusing so please bear with me. I have an array (listOfStates) of dictionaries. Where listOfStates has this structure: {stateName} - {stateCapital} {Alabama} - {Montgomery} {Alaska} - {Juneau} {Arizona} - {Phoenix} ... {West Virginia} - {Charleston} {Wisconsin} - {Madison} {Wyoming} - {Cheyenne} This is the code used ...

iPhone predicate: One of each.

I was wondering if it was possible to run a query using a predicate specifying "one of each." They do not seem to have anything similar to this in the predicate documentation. Appreciate any help or resources. UPDATE: I want to return every unique instance in a column which contains duplicates. ...