nspredicate

Creating NSPredicate dynamically by setting the key programmatically

亡梦爱人 提交于 2019-12-03 04:04:16
Why does the former of following snippets work while not the latter ? Snippet 1 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coin_unique == %@)", [NSNumber numberWithInt:species]]; Snippet 2 // Does NOT Work NSString *predicateText = @"coin_unique"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%@ == %@)", predicateText, [NSNumber numberWithInt:species]]; I have to dynamically create predicate depending upon the argument received in my method. coin_unique is a key, so it needs the %K format specifier: NSString *predicateText = @"coin_unique"; NSPredicate

Detect Phone number in a NSString

不羁的心 提交于 2019-12-03 03:52:07
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. This is what you are looking for, I think: NSString *myString = @"John @ 123-456-7890"; NSString *myRegex = @"\\d{3}-\\d{3}-\\d{4}"; NSRange range =

“Whole word” search in a NSString through NSPredicate

孤街醉人 提交于 2019-12-03 03:51:56
I would like to search if in the attribute description (an NSString instance) there is a given word. I tried with this predicate: [NSPredicate predicateWithFormat:@"description CONTAINS[cd] %@", theWord]; It works, but it finds also sub-words . For example, given theWord : Car it will mach also this description : A Christmas Carol Instead, I would like that my predicate will match only a , or christmas , or carol . (I'm using Core Data and NSFetchRequest.) Something like this? NSString *matchStr = @".*\\bCarol\\b.*"; NSPredicate *pred =[NSPredicate predicateWithFormat: @"description MATCHES %@

CloudKit - NSPredicate for finding all records that contain specified CKReference in a reference list

我与影子孤独终老i 提交于 2019-12-03 03:51:47
I am working on a CloudKit backed app with a Users record type that has a "following" reference list attribute. I am trying to construct a query to get every user that is following a specified user (i.e. those users in which the specified user appears as an entry in the following reference list). I am currently trying to construct my NSPredicate for the CKQuery as such: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN following", [[CKReference alloc] initWithRecordID:currentUserID action:CKReferenceActionNone]]; CKQuery *query = [[CKQuery alloc] initWithRecordType

NSPredicate predicateWithFormat:argumentArray: Only Evaluating First Argument

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 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:predicateString

How to query CloudKit for recordID IN [CKRecordID]

為{幸葍}努か 提交于 2019-12-03 03:04:24
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: Array members must conform to CKRecordValue: ( "", "", "", "", "" ) (CKRecordID) The other general parts

What is the best way to build a complex NSCompoundPredicate?

老子叫甜甜 提交于 2019-12-03 02:52:14
I need to build an NSPredicate with many pieces of data. For example in SQL I would do something like the following: SELECT * FROM TRANSACTIONS WHERE CATEGORY IN (categoryList) AND LOCATION IN (locationList) AND TYPE IN (typeList) AND NOTE contains[cd] "some text" AND DATE >= fromDate AND DATE <+ toDate I'm struggling with how to build this as an NSPredicate for use with Core Data. I've read the documentation... which only provides simplistic examples. If anybody can point me to a more complex example I would certainly appreciate it. Well, I had an answer out here for two years that many

CloudKit - NSPredicate for finding all records that contain specified CKReference in a reference list

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working on a CloudKit backed app with a Users record type that has a "following" reference list attribute. I am trying to construct a query to get every user that is following a specified user (i.e. those users in which the specified user appears as an entry in the following reference list). I am currently trying to construct my NSPredicate for the CKQuery as such: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN following", [[CKReference alloc] initWithRecordID:currentUserID action:CKReferenceActionNone]]; CKQuery

how handle error in NSPredicate

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: when i try to match regular expression for Data . sometime application crashes with error here is error description 'Can't do regex matching, reason: Can't open pattern U_REGEX_INVALID_RANGE (string Ertyu, pattern [a-Z], case 0, canon 0)' here is my code - (BOOL)isValidateString:(NSString *)inString ForRE:(NSString *)inRE { BOOL isValidate=NO; NSPredicate *thePredicate= [NSPredicate predicateWithFormat:@"SELF MATCHES %@", inRE]; isValidate= [thePredicate evaluateWithObject:inString]; return isValidate; } and in this method RE is getting from

NSPredicate on nested object / NSSet to filter the result during NSFetchRequest

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want a simple predicate that returns me all the groups which have mode = 0 and the mode of the enrollments in the group = 0 To be precise i need a predicate to access the nested object properties. Somehow a predicate like: [NSPredicate predicateWithFormat:@"mode = 0 AND enrollments.Enrollment.mode = 0"] the above predicate is wrong and obviously doesn't work. EDITED: I have given a go to the following predicate too but been unsuccessful. [NSPredicate predicateWithFormat:@"mode = 0 AND ALL ( SUBQUERY(enrollments,$varEnrollment,