nspredicate

Using @min,@max and etc inside a predicate?

血红的双手。 提交于 2019-11-29 00:26:43
Is it possible to use aggregate operator such as @min inside a predicate? BTW The predicate filters an array of objects. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF.score == @min.score"]; I know you can retrieve the min value using the key-value operators eg: NSNumber *minScore = [myArray valueForKeyPath:@"@min.score"]; So far I only get errors about the objects not being key value compliant for "@min". Thanks The reason that you're getting that error is that the predicate is being applied to each object in myArray , and those objects apparently don't support the key

NSPredicate 的使用(持续更新)

感情迁移 提交于 2019-11-28 22:20:52
NSPredicate 谓词工具一般用于过滤数组数据,也可用来过滤CoreData查询出的数据. 1). 支持keypath 2). 支持正则表达式 在使用之前先新建3个类 Teacher Info Address,详细代码如下 Info.h #import <Foundation/Foundation.h> @interface Info : NSObject @property (nonatomic, strong) NSString *classNum; @end Info.m #import "Info.h" @implementation Info @end Address.h #import <Foundation/Foundation.h> @interface Address : NSObject @property (nonatomic, strong) NSString *detailAddress; @end Address.m #import "Address.h" @implementation Address @end Teacher.h #import <Foundation/Foundation.h> #import "Info.h" #import "Address.h" @interface Teacher : NSObject

What's better way to build NSPredicate with to-many deep relationships?

雨燕双飞 提交于 2019-11-28 19:22:51
I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema for details: alt text http://img706.imageshack.us/img706/9974/screenshot20091220at124.png For getting all instance of EntityA which depend from EntityB.name I use the predicate like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY EntityB.name like 'SomeName'"]; What should be predicate for getting all instance of EntityA which depend from EntityC.name? I tried query like @"ANY EntityB.entitiesC.name like 'SomeName'" but get exception "multiple to-many keys not allowed here

Filtering NSDictionary with predicate

帅比萌擦擦* 提交于 2019-11-28 18:25: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. Assume that mainDict = { "1" = { "key1" = "ss", "key2" = "rr", "name" = "nm" }, "2" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, "3" = { "key1" = "nm", "key2" = "vv",

iOS CoreData NSPredicate to query multiple properties at once

做~自己de王妃 提交于 2019-11-28 17:33:53
问题 I am trying to use a UISearchBar to query multiple properties of a NSManagedObject I have a NSManagedObject called Person , every person has a name and socialSecurity property. Right now my code can perform a search (fetch) for one of those properties or the other, but not both at the same time. - (void) performFetch { [NSFetchedResultsController deleteCacheWithName:@"Master"]; // Init a fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity =

How to use the “ALL” aggregate operation in a NSPredicate to filter a CoreData-based collection

廉价感情. 提交于 2019-11-28 16:25:12
问题 Based on the data model below And based on user input I create a NSSet of managedObjects of entity Tag called selectedTags . My problem: [NSPredicate predicateWithFormat:@"ANY entryTags IN %@", selectedTags]; ... this will return any Entry with at least one entryTag that is in the selectedTags set. I want something along the lines of: [NSPredicate predicateWithFormat:@"ALL entryTags IN %@", selectedTags]; ... notice the only change is the "ANY" to "ALL". This illustrates what I want, but does

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

老子叫甜甜 提交于 2019-11-28 15:38:20
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] initWithObjects:sortDescriptor, nil]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"categories.name

NSPredicate 谓词的简单使用

让人想犯罪 __ 提交于 2019-11-28 15:37:30
NSPredicate:谓词,可用于数据查询、筛选。 运算符 用法 创建数组: Person * p1 = [Person new]; p1.name = @"p1"; p1.age = 1; Person * p2 = [Person new]; p2.name = @"p2"; p2.age = 2; Person * p3 = [Person new]; p3.name = @"ps3"; p3.age = 3; Person * p4 = [Person new]; p4.name = @"sp4"; p4.age = 4; NSArray * array = @[p1,p2,p3,p4]; 筛选小于3的对象 NSPredicate * predicate = [NSPredicate predicateWithFormat:@"age<3"]; NSArray * array1 = [array filteredArrayUsingPredicate:predicate]; 筛选范围内的对象 NSPredicate * predicate2 = [NSPredicate predicateWithFormat:@"age in {2,3} || name in {'p1','p2'}"]; NSArray * array2 = [array

Cannot use a predicate that compares dates in Magical Record

荒凉一梦 提交于 2019-11-28 14:34:11
I am making a method that will remove all of my NSManagedObjects that were not updated in the last sync. - (void)removeStaleObjects { // Delete objects that have not been updated in this sync. NSPredicate *stalePredicate = [NSPredicate predicateWithFormat:@"updated < %@", self.syncStart]; NSArray *staleObjects = [Node MR_findAllWithPredicate:stalePredicate]; for (Node *n in staleObjects) { [[NSManagedObjectContext MR_defaultContext] deleteObject:n]; } } The code keeps failing on the MR_findAll... line with [__NSDate objCType]: unrecognized selector sent to instance I have checked my syntax

core data - the primary key id of a row in the database

China☆狼群 提交于 2019-11-28 14:27:06
问题 Suppose I have a list of books stored in Core Data. I want to search for a book by it's primary key ID. I know the sqlite file created by Core Data has an ID column in each table, but this doesn't seem to be exposed to me in anyway. Does anyone have any recommendations? Thanks! 回答1: -[NSManagedObject objectID] is the unique ID for an object instance in Core Data. It can be serialized via -[NSManagedObjectID URIRepresentation] . You can retrieve the objectID from a persistent store coordinator