nspredicate

What is the bindings parameter for the block in predicateWithBlock: used for?

旧街凉风 提交于 2019-12-03 23:59:03
The declaration for +[NSPredicate predicateWithBlock:] looks like this: + (NSPredicate *)predicateWithBlock:(BOOL (^)(id evaluatedObject, NSDictionary *bindings))block Apple's documentation for the second parameter to the block, bindings , says that it is: The substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver. I can't figure out why this parameter is needed -- nor have I seen it being used anywhere. Why is it there? Also, do I need to look inside bindings when using a block based predicate with -[NSArray filteredArrayUsingPredicate

How to join two strings for NSPredicate, ie firstname and lastname

↘锁芯ラ 提交于 2019-12-03 23:36:22
I have a Person Object which has two NSString properties; firstName and lastName . I'm currently using an NSPredicate like so: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName contains[cd] %@) OR (lastName contains[cd] %@)", searchText, searchText]; So, for example, say I'm searching for the name "John Smith" . In my search bar if I type "Joh" , then John Smith will appear as an option. This is good and fine, but if I type in "John Sm" it will go blank. How can I join firstName and lastName in the predicate so if I was searching for "John Sm" then John Smith would still

NSPredicate - Unable to parse the format string [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-03 22:27:26
This question already has an answer here: Creating NSPredicate dynamically by setting the key programmatically 2 answers I am trying to write a NSPredicate to fetch rows with my_column value with this string " 193e00a75148b4006a451452c618ccec " and I get the below crash. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "my_column=193e00a75148b4006a451452c618ccec"' My predicate statement fetchRequest.predicate=[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"%@==\"%@\"",attributeName,itemValue]]; also tried this

avoid duplicate results on Core Data fetch

∥☆過路亽.° 提交于 2019-12-03 20:56:13
I have a subclass of the CoreDataTableViewController (subclass of UITAbleViewController dome by the people on Stanford done to link CoreData and TableViews). On this Class, I want to perform a fecth, sorting by an attribute called "definition" and the code which executes it is the following: - (void)setupFetchedResultsController{ NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:self.entity]; request.propertiesToFetch=[NSArray arrayWithObject:@"definition"]; request.returnsDistinctResults=YES; NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"%K != nil", @

NSPredicate to filter between two dates of NSString type

佐手、 提交于 2019-12-03 20:34:46
I've some data (as NSDictionary in an NSMutableArray ), a sample data is like, Consider each row as NSDictionary and entire table is an NSMutableArray contains events. I want to result between two dates, so I'm using NSPredicate to filter my data. Here's my code snippet for this, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Date >= %@ AND Date <= %@", startDate,endDate]; NSArray *filter = [arrayEvents filteredArrayUsingPredicate:predicate]; Test filtration : Case 1: NSString *startDate = @"01/07/14"; NSString *endDate = @"31/07/2014"; Output: All events (rows). Case 2: NSString

Core Data Predicate Filter By Today's Date

人盡茶涼 提交于 2019-12-03 20:07:10
问题 I had issues with this and I haven't found a proper answer on SO so I'll leave a small tutorial here. The goal is to filter fetched objects by today's date. Note: It's Swift 3 compatible. 回答1: You can't simply use to compare your date to today's date: let today = Date() let datePredicate = NSPredicate(format: "%K == %@", #keyPath(ModelType.date), today) It will show you nothing since it's unlikely that your date is the EXACT comparison date (it includes seconds & milliseconds too) The

What's the “cdl” do in TOKENMATCHES[cdl]?

半城伤御伤魂 提交于 2019-12-03 17:36:16
I came across TOKENMATCHES in minute 31 of Introducing CloudKit and was curious, so I did a google search and found very little about it outside of another StackOverflow post . NSPredicate(format: "ALL tokenize(%@, 'Cdl') IN allTokens", "after session") Actually, confusing things further, that post uses different syntax than the WWDC video: NSPredicate(format: "allTokens TOKENMATCHES[cdl] %@", "bob smith") As I understand it, these queries return any records that have all of the tokenized string arguments within one or more text fields. The latter case would fetch a record with, say, person

NSPredicate Core Data

独自空忆成欢 提交于 2019-12-03 17:14:00
What is the exact difference between LIKE [c]%@ and = [c]%@ in core data NSPredicate ? I want to search for a string that should exactly match the receiver. Example : NSArray *arrayNames = [context fetchObjectsForEntityName:NSStringFromClass([PatientFamilyMember class]) withSortColumn:nil withSortDescending:FALSE withPredicate:@"patientID = %@ && firstName=[c]%@ && relationship=[c]%@ && lastName=[c]%@", self.pfm.patientID, firstName, relationship, lastName]; This works but I have not understood the difference between using LIKE [c] and = [c]%@. The difference between LIKE and = in a predicate

Detect Phone number in a NSString

会有一股神秘感。 提交于 2019-12-03 15:01:20
问题 I want to extract the phone number from a NSString. For ex: In the string Call John @ 994-456-9966 , i want to extract 994-456-9966 . I have tried code like, NSString *nameRegex =@"(\(\d{3}\)\s?)?\d{3}[-\s\.]\d{4}"; NSPredicate *nameTest = [NSPredicate predicateWithFormat:@"ANY keywords.name CONTAINS[c] %@",nameRegex]; validationResult=[nameTest evaluateWithObject:phoneNo]; but i couldnt get exact result. Can anyone help me? Thanks in advance. 回答1: This is what you are looking for, I think:

NSPredicate that ignores whitespaces

允我心安 提交于 2019-12-03 14:00:36
I need to use NSPredicate to match two strings, case-insensitive, diacritic insensitive, and whitespace-insensitive . The predicate would look something like this: [NSPredicate predicateWithFormat:@"Key ==[cdw] %@", userInputKey]; The 'w' modifier is an invented one to express what I'd like to use. I can't just trim the userInputKey because the data-source "Key" values might have whitespaces in them too (they need those whitespaces, I can't just trim them beforehand). For example, given a userInputKey "abc" the predicate should match all of {"abc", "a b c", " a B C "} and so on. Given a