nspredicate

NSPredicate - Dynamic predicate with arguments

删除回忆录丶 提交于 2019-12-24 00:39:42
问题 I am new to NSPredicates, but I know the basics. This is how my predicate looks now: [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText]; What I want to do, is to be able to create a predicate like this (Pseudo code): NSPredicate *myPredicate = [NSPredicate predicateWithBaseString:@"name contains[c] _ARGUMENT_"]; And then use it in, for example a loop (pseudo code): for(NSString *searchString in self.allStrings) { NSPredicate *myNewPredicate = [myPredicate

predicateWithFormat vs stringWithFormat: is the former supposed to do the same as the latter?

半城伤御伤魂 提交于 2019-12-23 18:23:27
问题 I have an array with file names and I want to find all the names that end with e.g. 00001.trc when traceNum is 1. I tried this: NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH \"%05d.trc\"", traceNum]; and my predicate was SELF ENDSWITH "%05d.trc" instead of SELF ENDSWITH "00001.trc" I tried this: NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH %@%05d.trc%@", @"\"", traceNum, @"\""]; and I got an exception: Unable to parse the

iOS - NSPredicate string.length always evaluates to 0 when string starts with arithmetic operators + - * /

非 Y 不嫁゛ 提交于 2019-12-23 12:27:38
问题 I have a simple method that uses NSPredicate to return the number of rows where comments.length > 0. Problem is, I found that when the Comment column starts with + - * or /, the length property always evaluates to 0, and thus the row is excluded from the count. I opened the table in SQLite browser and verified the column is a VARCHAR. Using a SQLite query to check string length works just fine (LENGTH(ZComments) > 0), so this must be a CoreData issue. Here is my function... -(int

NSPredicate that references multiple fields on a to-many relationship?

对着背影说爱祢 提交于 2019-12-23 09:39:21
问题 I'm using a SQLite persistent store. I have a NSManagedObject class Den with a to-many relationship Bear . Bear has several fields: Bear: breed color age ... When I am building fetch requests for my Den objects, I can filter to objects that have a related Bear with a certain field value: NSPredicate *hasGrizzlyPred = [NSPredicate predicateWithFormat:@"ANY Bear.breed == 'grizzly'"]; Or I can just as easily search for a Den that has a brown bear: NSPredicate *hasBrownBearPred = [NSPredicate

How can I filter an array of NSDictionarys and NSDictionarys?

一世执手 提交于 2019-12-23 08:47:45
问题 I have an array which consists of several NSDictionaries with the keys: NSString *name NSString *ID NSDictionary *phoneNumbersDict Now I want to filter this array to find the one which has the phoneNumbersDict key @"keyIAmLookingFor" and the value @"valueIAmLookingFor" . NSMutableArray *addressBookPhoneIndividuals = [NSMutableArray array]; for (int i = 0; i < x; i++) { [addressBookPhoneIndividuals addObject:@{ @"name" : @"...", @"ID" : @"...", @"phoneNumbers" : @{...} }]; } 回答1: NSString

How to use NSPredicate to filter NSMutableSet which contains composite object from other Class?

淺唱寂寞╮ 提交于 2019-12-22 18:04:07
问题 Newbie Questions, I have 3 Class, 3 of them are subclass from NSOBject. Collection Class , have 2 properties, masterSong as NSMutableSet (strong, nonatomic) and listOfPlaylists as NSMutableArray (strong, nonatomic) Playlist Class Have 2 properties, playListName as NSString (copy, nonatomic) and songList as NSMutableArray (strong, nonatomic) 3 . Song Class Have 4 properties: title,artist,album, playtime as NSString (copy, nonatomic). masterSong will contain Song object, and listOfPlaylist will

using a @min in predicate

会有一股神秘感。 提交于 2019-12-22 17:57:11
问题 My current version for get @min or @max value is: for (NSManagedObject *destination in allSpecifics) { [allRates addObject:[destination valueForKey:@"rate"]]; } NSExpression *arrayExpression = [NSExpression expressionForConstantValue: allRates]; NSArray *argumentArray = [NSArray arrayWithObject: arrayExpression]; NSExpression* expression = [NSExpression expressionForFunction:@"min:" arguments:argumentArray]; id result = [expression expressionValueWithObject: nil context: nil]; NSNumber

NSPredicate Sort Array and Order DESC

拜拜、爱过 提交于 2019-12-22 13:55:11
问题 I have an NSMutableArray containing TBPosts that I would like to filter in descending order according to the commentsCount and likesCount of the TBPost . Initially, the first object in the filtered array will be the object with the largest number of comments and likes, which can be worked out by adding the two together. So I tried the following query and receive an Unable to Parse error. Please can you tell me where I am going wrong? [posts filterUsingPredicate:[NSPredicate

An NSPredicate that can recursively traverse an object graph?

强颜欢笑 提交于 2019-12-22 10:31:58
问题 I'm trying to filter an array of objects that essentially form a tree-style graph. what i want to do is to filter out all objects from this array whose visible property is NO, or if its parent/grandparent/etc visible property is true (child objects can have the visible property be YES while its parent can be NO). I'm unclear as to how i would go about this using NSPredicate syntax to keep searching the parent node until there are no parents or the visible property is found. Is there any way

How to filter array with NSPredicate for combination of words

好久不见. 提交于 2019-12-22 09:23:25
问题 [filteredArray filterUsingPredicate: [NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] %@", searchText]]; filteredArray contains simple NSStrings. [hello, my, get, up, seven, etc...]; It will give all strings that begin with searchText . But if string will be a combination of words like "my name is", and searchText = name . What would a NSPredicate look like to achieve this? UPDATE: And how would it have to be if i want to a result with searchText = name , but not with searchText = ame ?