nspredicate

NSPredicate for inner key in array of dictonary

…衆ロ難τιáo~ 提交于 2019-12-02 06:48:55
问题 i have an array of dictionay in the following format [ { "student": { "id": "1", "studentUserDetail": { "firstName": "Bonny", "lastName": "Roby" } } }, { "student": { "id": "1", "studentUserDetail": { "firstName": "Bonny", "lastName": "Kety" } } }, { "student": { "id": "1", "studentUserDetail": { "firstName": "Arther", "lastName": "Fone" } } }, ] In the above array i need to filter all elements containing a serachKey (eg Bonny) in the inside key student.StudentUserDetails.firstName . How can

swift NSPredicate logical OR

一世执手 提交于 2019-12-02 06:45:36
问题 I've got a single string substitution working with NSPredicate but returning core data records that contain either StringA or StringB doesn't seem to be something I can figure out. I want something like this: let filter = NSPredicate(format: ("%K = %@", "type", "StringA") OR ("%K = %@", "type", "StringB")) But of course that doesn't work. Help? 回答1: You have to specify a format string , followed by a comma-separated list of arguments to substitute into the format: let filter = NSPredicate

Apply NSPredicate on [(String, Array<String>)]

▼魔方 西西 提交于 2019-12-02 06:20:57
问题 I have data stored in this fashion, var data = [(String, Array<String>)]() Example Data: [(A, [Apple, Andy, Android]), (B, [Banana, Breakfast])] I am trying to apply a search filter on this data by using Predicate, Here is what I am tried and failed, func updateSearchResultsForSearchController(searchController: UISearchController) { let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text) let array = (data as NSArray).filteredArrayUsingPredicate

NSPredicate with nested arrays

浪子不回头ぞ 提交于 2019-12-02 05:29:33
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? For more complicated predicate string syntax I usually use predicateWithBlock to evaluate them instead, since it's much easier to debug and understand. However,

NSPredicate for to-many relationship, where a relationship (NSSet) must contain Entities defined in an NSArray

£可爱£侵袭症+ 提交于 2019-12-02 05:27:18
Given the following Core Data Model: -> : to-one releationship ->>: to-many relationship Entity A ->> Entity B Entity B -> A // each B belongs to exactly one A Entity B ->> B // a B can be related to other B's So in class A : @property (nonatomic, retain) NSSet *Bs; In class B : @property (nonatomic, retain) A *A; @property (nonatomic, retain) NSSet *Bs; Assume I have an NSArray *myArray containing (Bj, Bk) . What I want is to fetch all B 's which belong to Ax and are related to Bj and Bk : The code below works, but is completely ugly, since I have to hardcode the NSPredicate based on the

NSPredicate on nested array with NSDictionary as object

回眸只為那壹抹淺笑 提交于 2019-12-02 04:46:46
i have a NSDictionary like: { "2017-05-02" = ( { "always_valid" = 0; date = "2017-05-02"; from = "12:00"; to = "13:00"; }, { "always_valid" = 0; date = "2017-05-02"; from = "12:00"; to = "12:00"; }, { "always_valid" = 0; date = "2017-05-02"; from = "14:00"; "hourly_rate" = 12; to = "15:00"; } ); "2017-05-03" = ( { "always_valid" = 0; date = "2017-05-03"; from = "12:00"; to = "13:00"; } ); "2017-05-18" = ( { "always_valid" = 1; date = "2017-05-18"; from = "12:00"; to = "12:00"; } ); } i'm trying to apply NSPredicate *filter = [NSPredicate predicateWithFormat:@"always_valid = \"1\""]; NSArray

Create complicated NSCompoundPredicate in swift 3

烈酒焚心 提交于 2019-12-02 04:42:45
问题 I want to create a complicated NSCompoundPredicate in swift 3, however, I don't know how to do this. Suppose I have 5 predicates (p1,p2,p3,p4,p5). I want to implement below conditions: compound1 = (p1 AND p2 AND p3) // NSCompoundPredicate(type: .and, //subpredicates: predicates) compound2 = (p4 AND p5) // NSCompoundPredicate(type: .and, //subpredicates: predicates) compound3 = (compound1 OR compound2) // problem is here fetchRequest.predicate = compound3 NSCompoundPredicate as it's second

NSPredicate for exact match

故事扮演 提交于 2019-12-02 04:07:13
NSArray *arrData = [NSArray arrayWithObjects: @"cloud,country,plant", @"country,cloud,plant", @"country,plant,cloud", @"clouds,country,plant" ,@"country,clouds,plant", nil]; From above NSArray, I want objects which having a word "cloud" I tried below code NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(self beginswith %@ OR self contains[CD] %@)",@"cloud",@",cloud"]; NSArray *arrResult = [arrData filteredArrayUsingPredicate:predicate]; But it's giving all 5 objects in arrResult. But I need only 3 (0,1,2) objects. Try: NSPredicate* predicate = [NSPredicate predicateWithBlock:^

NSPredicate with OR returning error

十年热恋 提交于 2019-12-02 01:32:52
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]; NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"(toUser == %@)", userId]; And then

Create complicated NSCompoundPredicate in swift 3

╄→尐↘猪︶ㄣ 提交于 2019-12-02 00:39:58
I want to create a complicated NSCompoundPredicate in swift 3, however, I don't know how to do this. Suppose I have 5 predicates (p1,p2,p3,p4,p5). I want to implement below conditions: compound1 = (p1 AND p2 AND p3) // NSCompoundPredicate(type: .and, //subpredicates: predicates) compound2 = (p4 AND p5) // NSCompoundPredicate(type: .and, //subpredicates: predicates) compound3 = (compound1 OR compound2) // problem is here fetchRequest.predicate = compound3 NSCompoundPredicate as it's second argument gets array of NSPredicates that it doesn't desire. What is the best solution? NSCompoundPredicate