nspredicate

Core data subquery predicate

被刻印的时光 ゝ 提交于 2019-11-29 13:15:09
I'm trying to get a subquery predicate to work and I'm struggling. I have two entities. [League] <---->> [Game] Game has a property kickOffDate . I'd like to use a predicate to return all Leagues that have at least one Game with a kickOffDate today. I am using this predicate... // startOfDay and endOfDay are functions to return the given date with 00:00:00 and 23:59:59 respectively NSPredicate *startOfDayPredicate = [NSPredicate predicateWithFormat:@"SUBQUERY(games, $g, $g.kickOffDate >= %@).@count > 0", [self startOfDay:[NSDate date]]]; NSPredicate *endOfDayPredicate = [NSPredicate

How to search(Predicate) content from list like Xcode suggestion?

假装没事ソ 提交于 2019-11-29 12:57:25
I think everyone notice XCode suggestions list. Check this screenshot As per Apple document doesn't provide what expected ouptut . NSPredicate *inPredicate = [NSPredicate predicateWithFormat: @"attribute CONTAINS[cd] %@", aCollection]; Provide continuous search text only. Is this possible, How to search content like this? A possible solution, is to use a Regular Expression for that. We just need to insert .* between each letter (and before and after the string) which means "any character (except for line terminators)". It seems that's what's used for the search on XCode completion.

Core Data Many-to-Many Relationship NSPredicate

ぃ、小莉子 提交于 2019-11-29 12:31:35
I have a data model with a many-to-many relationship like EntityA <-->> EntityB <<--> EntityC . I used to query EntityA with different search criteria and I use NSCompoundPredicate with an array of NSPredicate s. On one of the predicate I wanted to query EntityA using EntityC . I tried to use the following SUBQUERY but it did not work. searchPredicate=[NSPredicate predicateWithFormat:@"(0 != SUBQUERY(EntityB, $B, (0 != SUBQUERY($B.EntityC, $EntityC, $EntityC.name like %@).@count)).@count)", name] And I got the following exception, Terminating app due to uncaught exception

NSPredicate for range between two dates is not working as expected

て烟熏妆下的殇ゞ 提交于 2019-11-29 11:14:06
I have these two NSDate s: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"MM/dd/yyyy"]; NSDate *rangeStart = [df dateFromString: @"03/03/2013"]; NSDate *rangeEnd = [df dateFromString: @"10/04/2013"]; And this predicate: request.predicate = [NSPredicate predicateWithFormat:@"createdDate >= %@ AND createdDate <= %@", rangeStart, rangeEnd]; But even though the second part of the predicate specifically uses a <= it is returning objects up until the day before (that is 10/03/2013 ). I also tried constructing the predicate like this: NSPredicate *dateStartPredicate =

NSPredicate with functions or selectors

試著忘記壹切 提交于 2019-11-29 10:39:00
I have a lot of people NSManagedObjects that I need filtering and was hoping to do it within the initial fetch instead of filtering the array afterwards. I've used selectors in predicates before, but never when fetching NSManagedObjects, for example I have all my employees and then i use this predicate on the NSArray... [NSPredicate predicateWithFormat:@"SELF isKindOfClass:%@", [Boss class]] ...but now I want to do a bit more math based on different attributes of my objects. I thought I could do something like... [NSPredicate predicateWithFormat:@"SELF bonusIsAffordable:%f",

Core Data unsupported predicate with ALL and IN

依然范特西╮ 提交于 2019-11-29 10:24:27
问题 I have a request like this : NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY attributes.attribute.attributeId IN %@", attributeIds]; That will return a list of objects, that have one ore more of the attributes I set. I want to get a list of objects that have all the attributes I pass, so I tried : NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ALL attributes.attribute.attributeId IN %@", attributeIds]; But I got an exception : 'NSInvalidArgumentException', reason:

NSPredicate BETWEEN with NSDate causes -[__NSDate constantValue]: unrecognized selector sent to instance 0x1e7ff0

大兔子大兔子 提交于 2019-11-29 10:08:39
I'm trying to fetch from Core Data records that have a startTime between two dates. Here's my code: NSDate *today = [NSDate date]; NSDate *distantFuture = [NSDate distantFuture]; // Create the predicate NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startTime BETWEEN %@", [NSArray arrayWithObjects:today, distantFuture, nil]]; NSLog(@"today: %@, distantFuture: %@", today, distantFuture); NSLog(@"predicate: %@", predicate); // Add the predicate to the fetchRequest [[[self fetchedResultsController] fetchRequest] setPredicate:predicate]; NSError *error; if (![[self

NSPredicate not executed

时光毁灭记忆、已成空白 提交于 2019-11-29 09:26:33
问题 This is quite funny. In my application I create thousands of entry in the database (in another thread, I'm using MagicalRecord). Everything seems working fine (from a background/foreground/context point of view). When, in the main thread, I try to fetch the "just inserted" data, I discovered the following behaviour: - (NSArray *) familiesInCompany:(Company *) company { NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"company == %@", company]; NSPredicate *predicate2 = [NSPredicate

Evaluating an NSPredicate on a NSArray (without filtering)

这一生的挚爱 提交于 2019-11-29 09:23:31
问题 Is it possible to evaluate a NSPredicate on a NSArray, without having the NSPredicate starting to filter out objects in the array? For instance, say I have the following predicate that just checks the number of objects in an array: NSPredicate *pred = [NSPredicate predicateWithFormat:@"count == 3"]; NSArray *list = [NSArray arrayWithObjects:@"uno", @"dos", @"volver", nil]; BOOL match = [pred evaluateWithObject:list]; This will crash, as pred will try to retrieve the "count" key from the first

NSPredicate on array of arrays

大城市里の小女人 提交于 2019-11-29 07:59:13
I have an array, that when printed out looks like this: ( ( databaseVersion, 13 ), ( lockedSetId, 100 ) ) Would it be possible to filter this using an NSPredicate (potentially by the index in the array). So something like: give me all rows where element 0 is 'databaseVersion'? I know that if I had an array of dictionaries I could do this with a predicate similar the one found here , but I found that when using dictionaries and storing a large amount of data, my memory consumption went up (from ~80mb to ~120mb), so if possible I would to keep the array. Any suggestions on how this might be done