nspredicate

iOS: NSPredicate doesn't work correct

≡放荡痞女 提交于 2019-12-13 04:13:22
问题 I try to express the search parameters with predicate: NSPredicate *predicate=[NSPredicate predicateWithFormat:@"name CONTAINS [cd] %@ OR code CONTAINS [cd] %@ OR currency CONTAINS [cd] %@ AND continent.paid == %@",searchString,searchString,searchString,[NSNumber numberWithBool:YES]]; I try to express search parameters for possible string records ONLY where continent.paid==YES. The problem is that last expression is ignored. The search returns data from continent.paid==NO as well with the

Swift 4: NSPredicate from UITextField and array of custom object

大兔子大兔子 提交于 2019-12-13 03:47:47
问题 I have an array of custom object. class MyObject { var code: String! var name: String! } I want to autocomplete a textField for that I have a tableView that I display when the user start writing. I have to filter my array datasource depending on the textField.text . For that I added a selector to the textField , then I test if there are names of elements in the array containing the textFiled.text using NSPredicate . This is the textField selector: @objc func textFieldDidChange(_ textField:

How to filter “active” HeartRate from HealthKit iOS using predicate?

空扰寡人 提交于 2019-12-13 03:18:06
问题 I am trying to fetch Heart Rate Data from HealthKit iOS by putting filter using HKQuery.predicateForObjects By using the following code: let predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext, allowedValues: ["active"]) var interval = DateComponents() interval.day = 1 let query = HKStatisticsCollectionQuery(quantityType: type, quantitySamplePredicate: predicate, options: [.discreteAverage], anchorDate: startDate, intervalComponents:interval) query

How to use NSPredicate with chained virtual property?

北城以北 提交于 2019-12-13 01:58:01
问题 Assume two ManagedObject backed by Sqlite: 1.) A User which has two properties, firstname and lastname and a virtual (transient) property fullname which is read-only. @interface User : NSManagedObject ... @property NSString *firstname; @property NSString *lastname; @property (readonly) NSString *fullname; @end @implementation User ... - (NSString*)fullname { return [NSString stringWithFormat:@"%@ %@", self.firstname, self.lastname]; } @end 2.) A Message which has besides several other

Union of two array of two different Objects

让人想犯罪 __ 提交于 2019-12-13 01:49:23
问题 I have two arrays of two different objects object 1: Class partner { var pImage: String? var pTimeStamp: NSDate? var pTitle: String? var ID: String? } object 2: Class customer { var cImage: String? var cTimeStamp: NSDate? var cTitle: String? var ID: String? var isCustomer : Bool? } I want to create an array (in a efficient way, of-course) out of these two array objects such that no partner and customer object with same ID ( cID,pID ) should repeat within new Array . Basically union of these

Checking to see if an NSString contains characters from a different NSString

本小妞迷上赌 提交于 2019-12-13 01:17:57
问题 I am looking for a way to compare two strings and see if the second string contains a character (letter, number, other) listed in the first, let me explain: For example: Imagine a password with only digits and "*" are allowed: Reference chain (1): "*0123456789" NSString format, no NSArray Work chain (2) = "156/15615=211" NSString format, How do I know that my chain 2 contains 2 characters (/=) which are not in my chain 1? To simplify the management letters allowed, I do not want to use

Is there any way to use NSPredicate to filter objects using distance calculation between points in CoreData

↘锁芯ラ 提交于 2019-12-12 20:31:37
问题 For example I have NSManagedObject with x and y double values. I want to get list of point that are located on some distance from provided one. I tried to use next predicate: [NSPredicate predicateWithFormat:@"(x-%f) (x-%f)-(y-%f) (y-%f) <= %f", point.x, point.x, point.y, point.y, 25*25] . But it doesn't work for some reason :(( . In my experiments I found out that predicate like (x-1)*2-x >= 0 returns 0 objects even if x is greater than 1, and (x+1)*2-x >= 0 returns all objects. So I suspect

NSPredicate instead of loop to filter an array of objects

谁说我不能喝 提交于 2019-12-12 20:24:54
问题 I have been told that I can use NSPredicate to duplicate the results of this method - (void) clearArrayOut { bool goAgain = false; for (int j=0; j<[array count]; j++) { if ([[array objectAtIndex:j] someMethod] == NO) { [array removeObjectAtIndex:j]; goAgain = true; break; } } if (goAgain) [self clearArrayOut]; } How can I make an NSPredicate that will filter an array based on the results of some method of a custom class's call? 回答1: To make a copy with the filter applied: NSArray

How to combine multiple nullable NSPredicates?

半腔热情 提交于 2019-12-12 18:18:24
问题 For eg, Something like: var finalPredicate = NSPredicate(format: "") if (screen != nil) { screenPredicate = NSPredicate(format: "screen = %@", screen!) finalPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [screenPredicate!]) } if (feature != nil) { featurePredicate = NSPredicate(format: "feature = %@", feature!) finalPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [finalPredicate, featurePredicate!]) } if (shouldDisplayPredicate != nil) { shouldDisplayPredicate =

Array of objects from array passing test

早过忘川 提交于 2019-12-12 18:15:16
问题 I have an NSArray of objects, which have a property id . I then have another NSArray with a selection of ids. I need to get all the objects in the first array which have the ids listed in the second array. Is it possible to do this without for loops (well 1 for loop is ok, but I'd like to avoid it). I know how to do this with 2 for loops, but this seems very inefficient. So basically I'm looking for the most efficient way. (The Id is an NSURL btw, so it can't be anything integer specific) 回答1