nspredicate

Filtering NSArray of NSDictionary objects using NSPredicate

人走茶凉 提交于 2019-11-29 21:56:54
I have an NSArray of NSDictionary objects. I want to filter the array based on keys of the dictionaries using NSPredicate. I have been doing something like this: NSString *predicateString = [NSString stringWithFormat:@"%@ == '%@'", key, value]; NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString]; NSArray *filteredResults = [allResultsArray filteredArrayUsingPredicate:predicate]; This works fine if they key passed in is one-word: Color, Name, Age. But it doesn't work if the key is multi-word, like: Person Age, Person Name. Basically, any key that contains a space, it

iOS CoreData NSPredicate to query multiple properties at once

此生再无相见时 提交于 2019-11-29 21:44:06
I am trying to use a UISearchBar to query multiple properties of a NSManagedObject I have a NSManagedObject called Person , every person has a name and socialSecurity property. Right now my code can perform a search (fetch) for one of those properties or the other, but not both at the same time. - (void) performFetch { [NSFetchedResultsController deleteCacheWithName:@"Master"]; // Init a fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"MainObject" inManagedObjectContext:self.managedObjectContext];

NSPredicate 'The left hand side for an ALL or ANY operator must be either an NSArray or NSSet'

梦想与她 提交于 2019-11-29 21:06:29
问题 Not totally sure why this isn't working now, i thought it had been working previously. Does anyone see an issue with this FetchRequest construction? - (NSArray *)entriesForDate:(NSDate *)date { NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY addedOn.unique like %@", [T3Utility identifierForDate:date]]; request.predicate = predicate; NSError *error = nil; NSArray *matches = [self.database

core data - the primary key id of a row in the database

情到浓时终转凉″ 提交于 2019-11-29 19:12:40
Suppose I have a list of books stored in Core Data. I want to search for a book by it's primary key ID. I know the sqlite file created by Core Data has an ID column in each table, but this doesn't seem to be exposed to me in anyway. Does anyone have any recommendations? Thanks! Barry Wark -[NSManagedObject objectID] is the unique ID for an object instance in Core Data. It can be serialized via -[NSManagedObjectID URIRepresentation] . You can retrieve the objectID from a persistent store coordinator with -[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:] and then get the

Case insensitive NSPredicate for strings from an array?

时光毁灭记忆、已成空白 提交于 2019-11-29 19:05:47
问题 I have a situation where I want to fetch objects from my core data store by the username key, but I want the comparison to be case-insensitive. The predicate I have is this: username IN $usernames I then do a variable substitution with an array of strings that are the usernames I want to find. It works but is case-sensitive. I'd like to do something like this, I think: username IN[c] $usernames Unfortunately that doesn't appear to work. The string comparison must still be happening in a case

NSPredicate something equivalent of SQL's GROUP BY

不羁岁月 提交于 2019-11-29 18:21:29
问题 To simplify: There are 3 columns in a table named cards. id packTitle term id is a column - integers from 0.....100 packTitle - string describing packs, lets say there are 3 kinds of pack PACK1, PACK2, PACK3 term - different unsorted names of 101 items. by SQL statement select packTitle from cards group by packTitle; I can get list of 3 items. Could you suggest NSPredicate equivalent of SQL statement GROUP BY. I need to get an array to populate in UITableView. 回答1: CoreData is an object graph

Help with CoreData making a NSPredicate - Recursive Searching

淺唱寂寞╮ 提交于 2019-11-29 16:19:18
I am using CoreData for an iPhone project and I am stuck trying to build a predicate. My core data entity is Folder parent - Point to the folder class parent, can be null and is one to one. secure - An enum that holds the security type. The problem I have is that I am trying to make it so I don't show any folder that are in a secure folder. Right now my predicate looks something like this. NSPredicate *pred = [NSPredicate predicateWithFormat:@"secure = $@ AND (parent = %@ OR parent.secure = %@)",[NSNumber numberWithInteger:kNoSecurity], [NSNull null], [NSNumber numberWithInteger:kNoSecurity]];

Core Data NSPredicate for date

冷暖自知 提交于 2019-11-29 14:13:10
In my model I have date attribute and I set it [NSDate date] , but getting with predicate like NSPredicate *predicate = [NSPredicate predicateWithFormat: @"date==%@ ,date]; returns notting. I know the problem is when I set [NSDate date] it stores also time and NSPredicate always return empty data. Is there any way to convert "date==%@" part to only look for date? cancerian NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@)", startDate, endDate]; 来源: https://stackoverflow.com/questions/12500041/core-data-nspredicate-for-date

How to speed up updating relationship among tables, after one or both tables are already saved?

微笑、不失礼 提交于 2019-11-29 13:54:01
Question: Update and save fast, relationship between tables with lots of data after both or one of the table is already saved. I have five tables TvGenres, TvSubgenre, TvProgram, Channels, TvSchedules with the relationship between them as shown in below image Now the problem is all data downloading happens in sequence based on previous data and unlike SQLite, I need to set relationship between them and to do that I have to search table again and again and set the relation between them which is time-consuming so how can I do that faster I use 2 different approaches to solve but both are not

CoreData predicate: string property length?

余生长醉 提交于 2019-11-29 13:34:39
Say if I have an entity Fragment , it has an attribute 'text' which is a string, I want to query the list of Fragment whose text is of length 5: [NSPredicate predicateWithFormat:@"position == %@ AND text.length == %d", pos, 5]; It does not work (ie returns no result), but if I remove text.length in the query it works and I'm certain that there are texts of length 5, so what do I need to change it to? Thanks! There is no length attribute for strings in the NSPredicate . Use regex instead. Your predicate should look as follows: [NSPredicate predicateWithFormat:@"position == %@ AND text MATCHES %