nspredicate

How to use the “IN” Operator with a Predicate

与世无争的帅哥 提交于 2019-12-10 22:42:30
问题 How to write NSPredicate to fetch the rows that matches with values in the array? E.g: [NSPredicate predicateWithFormat:@"UserName IN %@",UserIDArray]; If UserIDArray contains ID of users, how does one fetch the user name which matches with the values in this array? 回答1: Let me start with this advice. Core Data is not SQL. Entities are not tables. Objects are not rows. Columns are not attributes/properties. Core Data is an object graph management system that may or may not persist the object

NSPredicate with multiple comparisons for one query string

偶尔善良 提交于 2019-12-10 20:49:08
问题 I was wondering if there is a way to simplify an NSPredicate that takes in a single query string for multiple comparison targets. I'm searching multiple attributes of a core data entity for the same query string. My current query looks something like this... [NSPredicate predicateWithFormat:@"(attributeA contains[cd] %@) OR (attributeB contains[cd] %@) OR (attributeC contains[cd] %@)", searchString, searchString, searchString]; Note that this works perfectly, but it does look a bit unsightly.

Speed: iOS Using NSPredicate filterUsingPredicate vs. for loop

假如想象 提交于 2019-12-10 18:14:58
问题 I need to filter an NSMutableArray of custom objects and was wondering about whether or not one of the following is BETTER than the other in terms of speed/runtime, or if they are virtually the same: (1) Using [array filterUsingPredicate:predicate], or (2) Using a for loop to iterate through all elements and check if they satisfy the criteria or not myself. I only ask this because I think the criteria each object must satisfy could vary so making the predicate could be tricky. Thanks in

Filter Array of Objects with NSPredicate based on NSInteger property in super class

流过昼夜 提交于 2019-12-10 16:49:13
问题 I've got the following setup: @interface Item : NSObject { NSInteger *item_id; NSString *title; UIImage *item_icon; } @property (nonatomic, copy) NSString *title; @property (nonatomic, assign) NSInteger *item_id; @property (nonatomic, strong) UIImage *item_icon; - (NSString *)path; - (id)initWithDictionary:(NSDictionary *)dictionairy; @end And #import <Foundation/Foundation.h> #import "Item.h" @interface Category : Item { } - (NSString *)path; @end I've got an array with Category instances

NSPredicate not working with array of dictionaries

雨燕双飞 提交于 2019-12-10 16:46:45
问题 I have an NSPredication with format like this: @"Status CONTAINS[cd] shipped" I have an array of dictionary, here's an example: { { Category = "Category 4"; Comp = "Category 4"; Depth = 02; Grade = New; Length = 02; Location = "Thousand Oaks, CA"; Name = "3ply Mat"; Owner = "Owner 3"; PUP = 2; Status = Shipped; "Unit Number" = 20110507113852351; Width = 02; }, { Category = "Category 4"; Comp = "Category 4"; Depth = 02; Grade = New; Length = 02; Location = "Thousand Oaks, CA"; Name = "3ply Mat

NSPredicate with SubQuery

◇◆丶佛笑我妖孽 提交于 2019-12-10 15:43:16
问题 I have this relationship: player <—>> games <<—> quiz and want to get all quiz not in a game of a player, like SELECT * FROM ZQUIZ WHERE Z_PK NOT IN (SELECT ZQUIZ FROM ZGAME WHERE ZPLAYER == 1) Can anybody help? 回答1: This can be done with a SUBQUERY clause. If myPlayer is the player in question: let predicate = NSPredicate(format:"SUBQUERY(games,$g, $g.player == %@).@count == 0", myPlayer) 来源: https://stackoverflow.com/questions/35688892/nspredicate-with-subquery

Filter data from array of Dictionary using predicate iOS SDK

一世执手 提交于 2019-12-10 15:07:33
问题 Hello guys i have an array of dictionary, can you guys tell me how can i filter this data based on dictionary keys. ( { "mall_id" = M0550; "mall_name" = "Amrita Shopping Complex"; }, { "mall_id" = M0509; "mall_name" = "Ashoka Market"; }, { "mall_id" = M0943; "mall_name" = "Biju Pattnaik Commercial Complex"; }, { "mall_id" = M0457; "mall_name" = "BMC Bhawani Mall"; }, { "mall_id" = M0460; "mall_name" = "BMC Keshari Mall"; }, { "mall_id" = M0571; "mall_name" = "BMC Market Complex"; }, { "mall

NSPredicate predicateWithFormat passing in name of attribute

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 14:35:28
问题 Simple question regarding NSPredicate's. I'm trying to construct my predicate with "passed in" values like so : NSPredicate* currentPredicate = [NSPredicate predicateWithFormat:@"%@ == %@",key,[changesDict valueForKey:@"Id"] ]; However, I haven't been able to get this to work correctly. If I insert the actual value I pass through it does work though. So this works : NSPredicate* currentPredicate = [NSPredicate predicateWithFormat:@"contactId == %@",[changesDict valueForKey:@"Id"] ]; (Notice i

Filtering Realm objects with Swift

前提是你 提交于 2019-12-10 13:42:11
问题 I always get the following error when trying to filter my Realm database using NSPredicate : Property 'text' is not a link in object of type 'getType' I want to filter my Realm database to show only the items that have some specific text in them. This is what I've tried: let realm = try! Realm() let predicate = NSPredicate(format: "typez.text.filter = 'special'") let filterThis = realm.objects(Publication).filter(predicate) print(filterThis) The relevant portion of my model classes is: class

How to get all items with NSPredicate CONTAINS IN array

我是研究僧i 提交于 2019-12-10 13:28:26
问题 I have an array of objects and each has an id, and i want to get all items where item.objectID contains in an array of ids, how can i get that result ? What i tried to do but i have an error on creating predicateWithFormat: Unable to parse the format string : NSString *predicateFormat = [NSString stringWithFormat:@"SELF.itemID CONTAIN IN (1,2,3,4,5,6,7,8)"]; NSPredicate *predicate = [NSPredicate predicateWithFormat: predicateFormat]; filteredData = [localData filteredArrayUsingPredicate