nspredicate

How to fetch even and odd values from core data using Predicate

一曲冷凌霜 提交于 2020-01-13 20:28:50
问题 I want to fetch even and odd values from my core data entity, please look into below code and correct, because its crashing the app. NSPredicate *predicate; if ([leadFilter.rank isEqualToString:@"Even"]) { predicate = [NSPredicate predicateWithFormat:@"(street%2) = 0"]; } else predicate = [NSPredicate predicateWithFormat:@"street%2 != 0)"]; [predicateArray addObject:predicate]; Its saying unable to parse street%2=0. 回答1: You can do this directly in Core Data, but the syntax is a little hairy.

How to fetch even and odd values from core data using Predicate

不问归期 提交于 2020-01-13 20:28:41
问题 I want to fetch even and odd values from my core data entity, please look into below code and correct, because its crashing the app. NSPredicate *predicate; if ([leadFilter.rank isEqualToString:@"Even"]) { predicate = [NSPredicate predicateWithFormat:@"(street%2) = 0"]; } else predicate = [NSPredicate predicateWithFormat:@"street%2 != 0)"]; [predicateArray addObject:predicate]; Its saying unable to parse street%2=0. 回答1: You can do this directly in Core Data, but the syntax is a little hairy.

Use NSPredicate to add up all values

試著忘記壹切 提交于 2020-01-11 11:49:34
问题 I have a program which uses Core Data. I was kinda cheating when adding the numeric values from each entity in a loop. I read about using NSPredicate to filter the data, but I don't know how to manipulate the data or how the results are even stored. Thanks. 回答1: You can do it in two steps, if that fits your requirements. First filter your data with your NSPredicate and keep it all in an NSArray . Then use a compound operator with Key-Value Coding to get the sum. Below is an example of how it

Use NSPredicate to add up all values

谁说我不能喝 提交于 2020-01-11 11:46:08
问题 I have a program which uses Core Data. I was kinda cheating when adding the numeric values from each entity in a loop. I read about using NSPredicate to filter the data, but I don't know how to manipulate the data or how the results are even stored. Thanks. 回答1: You can do it in two steps, if that fits your requirements. First filter your data with your NSPredicate and keep it all in an NSArray . Then use a compound operator with Key-Value Coding to get the sum. Below is an example of how it

How to search(Predicate) content from list like Xcode suggestion?

若如初见. 提交于 2020-01-10 04:44:05
问题 I think everyone notice XCode suggestions list. Check this screenshot As per Apple document doesn't provide what expected ouptut. NSPredicate *inPredicate = [NSPredicate predicateWithFormat: @"attribute CONTAINS[cd] %@", aCollection]; Provide continuous search text only. Is this possible, How to search content like this? 回答1: A possible solution, is to use a Regular Expression for that. We just need to insert .* between each letter (and before and after the string) which means "any character

coredata-deleting from database and making request

喜你入骨 提交于 2020-01-07 04:41:31
问题 Hi I am a bit noob whit core-data so I request for your answer, I can pull out data from database whit this functions: NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; [[selectedObject valueForKey:@"SOMECOLLUMNNAME"] description]; But I have a really big problems whit deleting from database I have read that I should use NSPredicate I read the tutorial but I do no figure out how can I write a simple DELETE * FROM Table t WHERE t.date == 01.01

fetching core data values using predicate

僤鯓⒐⒋嵵緔 提交于 2020-01-07 04:40:50
问题 my sqlite have items in one of the entity and i wish to retrieve them out according to their categoryID e.g. categoryID 1 have 7 items and categoryID 2 have 5 items , when i clicked on an IBAction it will come to this method and retrieve according to my global.clickedTag but i'm unable to retrieve the values , any idea why? -(NSMutableArray*)fetchItem:array{ [self managedObjectContext]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"IItem" inManagedObjectContext

UITableView doesn't refresh when NSPredicate set

流过昼夜 提交于 2020-01-06 18:43:31
问题 Preface: I tried [self.tableview reloadData] . My app doesn't crash, but it doesn't refresh, either. I'm trying to display 2 sets of results on one TableViewController depending upon whether an NSPredicate is set. I'm trying to find a jargon free answer how I can update a UITableViewController once a predicate is set. My data displays properly the when the view initially loads. My predicate sets properly, all the log statements I've thrown in return values...but nothing happens when it's set.

Chaining replacements don't work in NSPredicate

一笑奈何 提交于 2020-01-06 14:44:27
问题 The following code raises a question NSPredicate * myPred = [NSPredicate predicateWithFormat:@"$my_var.employees.@count == 3"]; NSExpression * myExpr = [NSExpression expressionForKeyPath:@"$my_var.test"] ; NSPredicate * myPredBis = [myPred predicateWithSubstitutionVariables:@{@"my_var" : myExpr}] ; NSExpression * myExpr2 = [NSExpression expressionForKeyPath:@"self"] ; NSPredicate * myFinalPred = [myPredBis predicateWithSubstitutionVariables:@{@"my_var": myExpr2}]; NSLog(@"%@", myFinalPred) ;

How can I modify NSPredicate to ignore whitespaces in Swift?

允我心安 提交于 2020-01-06 11:48:25
问题 I am filtering a CNContact phoneNumbers to see if dialed number is contained within the contact's number. Bellow attached code works fine, but..... My problem: If the phone number has no white spaces inside, works ok but if I search "0761" and contact's phone number is "076 1", it ignores it. I am using NSPredicate . Code: func filterAndGetCurrentPhoneNumber(c: CNContact) -> String{ let searchPredicate = NSPredicate(format: "SELF.value.stringValue CONTAINS[c] %@", self.txtf_dial.text!) let