nspredicate

What is wrong in my nested SUBQUERY predicate?

纵饮孤独 提交于 2019-12-30 06:38:05
问题 I have the data model you can see below, and a nested SUBQUERY predicate, but in somehow it just not works. Any idea how to correct it? I figured out, this here down is working finally: [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $B, SUBQUERY($B.cs, $C, $C.ds.name != \"xxx\").@count > 0).@count > 0"]; 回答1: Ok, so here is the working solution: [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $B, SUBQUERY($B.cs, $C, $C.ds.name != \"xxx\").@count > 0).@count > 0"]; 来源: https://stackoverflow

Sorting NSMutableArray using SortDescriptor AND Predicate possible?

偶尔善良 提交于 2019-12-30 03:27:08
问题 I have an array of type "Restaurant" which has an NSSet of "Rating." Rating has an ID and a value. I want to sort the array of Restaurant's by rating with an ID of 01, from high to low. Something like the following, but how do I use the predicate and sort descriptor together on originalArray? NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Rating.rating_id=%d", ratingID]; NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"currentValue" ascending:YES]; NSArray

Filtering NSDictionary with predicate

陌路散爱 提交于 2019-12-29 03:21:08
问题 I am using a NSDictionary that itself contains dictionaries some keys and its values.The format is like , { "1" = { "key1" = "ss", "key2" = "rr", "name" = "nm" }, "2" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, "3" = { "key1" = "nm", "key2" = "vv", "name" = "gf" }, "4" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, } I need to filter with the case that key1 should be "tt" and key2 should "vv" using NSPredicate. 回答1: Assume that mainDict = { "1" = { "key1" = "ss", "key2" = "rr",

Core Data: NSPredicate for many-to-many relationship. (“to-many key not allowed here”)

 ̄綄美尐妖づ 提交于 2019-12-29 02:33:34
问题 I have two entities named "Category" and "Article" which have a many to many relationship. I want to form a predicate which searches for all articles where category.name is equal to some value. I have the following: NSEntityDescription *entityArticle = [NSEntityDescription entityForName:@"Article" inManagedObjectContext:managedObjectContext]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc]

Form NSPredicate from string that contains id's

余生长醉 提交于 2019-12-29 01:23:11
问题 I have this problem where I can't think of how to write this predicate. I have an Entity called Contact, it has a string property "pages", let's say contact.pages = @"1,5,11,15,17"; There is a lot of contacts in my database, and I want to fetch only these contacts that contains a certain id. So let's say I want to fetch only these contacts, which pages contains id @"1". I can think of something like this, NSPredicate* predicate = [NSPredicate predicateWithFormat:@"self.pages CONTAINS %@",

NSPredicate for an NSManagedObject's string attribute's length

和自甴很熟 提交于 2019-12-28 18:29:52
问题 Could someone please help me define a predicate that returns only NSManagedObject's who's "letters" attribute length is within a certain range? Here's the example I've been trying, I've got a feeling it's the letters.length notation, I've also tried the kvc letters.@length with no success.. What am I doing wrong? NSManagedObjectContext *context = ...; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Word"

NSPredicate

别说谁变了你拦得住时间么 提交于 2019-12-28 10:14:48
【iOS开发技术】NSPredicate谓词的用法 数组过滤 http://blog.csdn.net/lmf208/article/details/38345321 NSPredicate是一个Foundation类,它指定数据被获取或者过滤的方式。它的查询语言就像SQL的WHERE和正则表达式的交叉一样,提供了具有表现力的,自然语言界面来定义一个集合被搜寻的逻辑条件。 相比较抽象的谈论它,展示NSPredicate的使用方法更加容易,所以我们来重新审视 NSSortDescriptor 中使用的示例数据集吧: 索引 1 2 3 4 名 Alice Bob Charlie Quentin 姓 Smith Jones Smith Alberts 年龄 24 27 33 31 @ interface Person : NSObject @property NSString *firstName; @property NSString *lastName; @property NSNumber *age; @end @implementation Person - (NSString *)description { return [NSString stringWithFormat:@ "%@ %@", self.firstName, self.lastName]; } @end

NSPredicate

老子叫甜甜 提交于 2019-12-28 10:14:14
转: 点击打开链接 NSPredicate是一个Foundation类,它指定数据被获取或者过滤的方式。它的查询语言就像SQL的WHERE和正则表达式的交叉一样,提供了具有表现力的,自然语言界面来定义一个集合被搜寻的逻辑条件。相比较抽象的谈论它,展示NSPredicate的使用方法更加容易,所以我们来重新审视 NSSortDescriptor 中使用的示例数据集吧: 索引 1 2 3 4 名 Alice Bob Charlie Quentin 姓 Smith Jones Smith Alberts 年龄 24 27 33 31 @interface Person : NSObject @property NSString *firstName; @property NSString *lastName; @property NSNumber *age; @end @implementation Person - (NSString *)description { return [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName]; } @end #pragma mark - NSArray *firstNames = @[ @"Alice", @"Bob", @"Charlie", @"Quentin

NSPredicate

主宰稳场 提交于 2019-12-28 10:10:44
NSPredicate Mattt Thompson 撰写、 Zihan Xu翻译、 发布于2013年7月15日 NSPredicate 是一个Foundation类,它指定数据被获取或者过滤的方式。它的查询语言就像SQL的 WHERE 和正则表达式的交叉一样,提供了具有表现力的,自然语言界面来定义一个集合被搜寻的逻辑条件。 相比较抽象的谈论它,展示 NSPredicate 的使用方法更加容易,所以我们来重新审视 NSSortDescriptor 中使用的示例数据集吧: 索引 0 1 2 3 名 Alice Bob Charlie Quentin 姓 Smith Jones Smith Alberts 年龄 24 27 33 31 Objective-C @interface Person : NSObject @property NSString *firstName; @property NSString *lastName; @property NSNumber *age; @end @implementation Person - (NSString *)description { return [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName]; } @end #pragma mark -

NSPredicate

狂风中的少年 提交于 2019-12-28 10:10:28
NSPredicate是一个Foundation类,它指定数据被获取或者过滤的方式。它的查询语言就像SQL的WHERE和正则表达式的交叉一样,提供了具有表现力的,自然语言界面来定义一个集合被搜寻的逻辑条件。 相比较抽象的谈论它,展示NSPredicate的使用方法更加容易,所以我们来重新审视 NSSortDescriptor 中使用的示例数据集吧: 索引 1 2 3 4 名 Alice Bob Charlie Quentin 姓 Smith Jones Smith Alberts 年龄 24 27 33 31 @ interface Person : NSObject @property NSString *firstName; @property NSString *lastName; @property NSNumber *age; @end @implementation Person - (NSString *)description { return [NSString stringWithFormat:@ "%@ %@", self.firstName, self.lastName]; } @end #pragma mark - NSArray *firstNames = @[ @ "Alice", @ "Bob", @ "Charlie", @ "Quentin" ]