nspredicate

NSPredicate predicateWithFormat:argumentArray: Only Evaluating First Argument

谁说胖子不能爱 提交于 2019-12-21 12:27:08
问题 I'm having some trouble using NSPredicate predicateWithFormat:argumentArray :. In this example, serverIDList is array of strings. Results is an array of NSManagedObjects with an attribute named "flid" which is a string. NSMutableString *predicateString = [[NSMutableString alloc] init]; [predicateString appendString:@"(flid IN %@)"]; [results filterUsingPredicate:[NSPredicate predicateWithFormat:predicateString argumentArray:serverIDList]]; The problem is that [NSPredicate predicateWithFormat

Core Data: Keypath Error Not Found in Entity <NSSQLEntity Studies id=3>

你离开我真会死。 提交于 2019-12-21 07:08:51
问题 Could any one tell me what's the wrong with this code? It raises the following error and cause application to crash: reason: 'keypath Studies.patients.PatientName not found in entity <NSSQLEntity Studies id=3>' Code: - (void)viewDidLoad { [super viewDidLoad]; test_coredataAppDelegate *appDelegate = (test_coredataAppDelegate *)[[UIApplication sharedApplication] delegate]; self.context = appDelegate.managedObjectContext; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

Core data to-many NSPredicate with AND

蓝咒 提交于 2019-12-21 02:54:17
问题 I'm trying to write a query for the find-as-you-type search bar. What I want to do is query "Kind", and return any Kinds for which there is a LocalName with ('name' LIKE %@ AND localeIdentifier == %@). If I'm only searching the names (so ignoring the localeIdentifier), I could do something like this: ANY localized.name LIKE %@ What I want is something more like ANY localized.(name LIKE %@ AND localeIdentifier == %@) To sum up, searching "Kind", any one item in the to-many relationship

How to query CloudKit for recordID IN [CKRecordID]

扶醉桌前 提交于 2019-12-20 12:38:45
问题 My predicate wants to exclude some records that are already downloaded and available in a [CKRecordID]. Now I can query 1 CKRecordID[0], but not the [CKRecordID] array. How can I query the array? let excludeIDs: [CKRecordID] This works: let pred1 = NSPredicate(format: "NOT(recordID = %@)", excludeIDs[0]) But this doesn't: let pred1 = NSPredicate(format: "NOT(recordID IN %@)", excludeIDs) ERROR: loadImageCompareRecordIDsAndEndDateThatHaveNotEnded Error: Invalid predicate: Invalid predicate:

Using NSPredicate to filter array of arrays

荒凉一梦 提交于 2019-12-20 10:20:51
问题 I have the following situation: NSArray( NSArray( string1, string2, string3, string4, string5, ) , NSArray( string6, string7, string8, string9, string10, ) ) Now I need a predicate that returns the array that contains a specific string. e.g. Filter Array that contains string9 -> I should get back the entire second array because I need to process the other strings inside that array. Any ideas? 回答1: Just for completeness: It can be done using predicateWithFormat: : NSArray *array = @[ @[@"A", @

NSPredicate: Fetch one of each kind

本秂侑毒 提交于 2019-12-20 09:53:15
问题 I want to create an NSFetchRequest for objects like this: The Object is Car which has an attribute color . I have four cars: car1.color = red car2.color = red car3.color = blue car4.color = green I want to create an NSPredicate that selects only one car for each color(it doesn't matter which car it selects. How can I achieve this? In fact I'm looking for something similar like a DISTINCT in SQL 回答1: Core Data does support fetching distinct values. Apple even provides sample code here: http:/

Core Data, try to use NSPredicate to filter a toMany relationship set but get the “to-many key not allowed here” error

五迷三道 提交于 2019-12-20 08:56:12
问题 Here is the model I have: http://www.girardet.ch/model.png My goal is to retrieve all the Quotes with these criterias: belong to a specific theme : the name_en attribute of Themes order by relevancy filtered by Authors (with the alias attribute of Authors) Here is my code: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"ThemeEntries" inManagedObjectContext:_context]; [fetchRequest setEntity:entity];

NSPredicate for time interval

陌路散爱 提交于 2019-12-20 07:21:39
问题 I have one table with 4 fields startdate ,enddate, starttime and endtime. I need to set predicate something like if startdate<= currentdate and currentdate <= enddate if starttime <= currenttime and endtime <= endtime else starttime <= currenttime and currenttime<= 23.00 or 0.00 <= currentime and currentime <= endtime How i set predicate for this type of condition.Current date and current time is the my system time in gmt. 回答1: You can use NSCompoundPredicate Create NSMutableArray to hold

NSPredicate with nested arrays

若如初见. 提交于 2019-12-20 05:27:05
问题 I have the following object structure Categories: subcategories (nsarray of subcategory) Subcategory: questions (nsarray of question) Question: question (nsstring) answer (nsstring) What I need is to search any question with the given substring The following predicate is not working: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY subcategories.questions.question CONTAINS[cd] %@", substring]; How to properly fetch them? 回答1: For more complicated predicate string syntax I

NSPredicate with OR returning error

北城余情 提交于 2019-12-20 03:33:21
问题 I have a problem with the following predicate: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(creatorUserRecordID == %@) OR (toUser == %@)", userId, userId]; When I use it in query CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Message" predicate:predicate]; I have an error that says: 'CKException', reason: 'Unexpected expression'. When I use these two seperately like this: NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"(creatorUserRecordID == %@)", userId]