nspredicate

NSPredicate unable to parse format string

丶灬走出姿态 提交于 2019-12-06 05:04:42
问题 I can't see any problem with these line of code. Why can't it parse? [NSPredicate predicateWithFormat:@"(username CONTAINS[cd] %1$@) || " "(userId CONTAINS[cd] %1$@) || " "(firstname CONTAINS[cd] %1$@) || " "(lastname CONTAINS[cd] %1$@)", searchString]" The Log doesn't help either. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(username CONTAINS[cd] %1$@) || (userId CONTAINS[cd] %1$@) || (firstname CONTAINS[cd] %1$@) ||

NSPredicate with regex to check alphanumeric

僤鯓⒐⒋嵵緔 提交于 2019-12-06 03:54:01
I want to check string with regex in Objective c. My code NSString *regexAmazonOrder =@"[a-zA-Z0-9]*"; NSPredicate *predicateAmazonOrder = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regexAmazonOrder]; if([predicateAmazonOrder evaluateWithObject:cardNumber.text]) { NSLog(@"Its coming inside AMAZON ORDER EVALUATIONS"); ... } But its not working. Help me out. I know its simple but eating my mind!!! Thanks Try like this: (Untested, just to give you an starter) NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[a-z0-9]*" options

NSPredicate - case insensitive filtering for multiple conditions

左心房为你撑大大i 提交于 2019-12-06 02:59:53
问题 I'm using following NSPredicate for filtering, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName CONTAINS %@ ) OR (lastName CONTAINS %@ )OR (UserName CONTAINS %@ ) ", myText,myText,myText]; NSArray *filtered = [responseArray filteredArrayUsingPredicate:predicate]; It works fine, but it's case-sensitive. I need the filtering should be case insensitive. I've tried, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY firstName CONTAINS %@ ) OR (ANY lastName

NSPredicate to filter only on “year” part of a date field

杀马特。学长 韩版系。学妹 提交于 2019-12-06 01:37:31
问题 I have an entity with a date field and I would like to select the records for a given year. How to build a NSPredicate for the job? Didn't find anything about date functions (if any) in Core Data thanks 回答1: A possible method: Step 1) See "Creating a Date from Components" from Apple's "Date and Time Programming Guide." Make an NSDate representing the beginning of the year, and an NSDate representing the end of the year. Step 2) Then you could build a predicate that searches for objects with

Determining if an NSDate is today in NSPredicate

守給你的承諾、 提交于 2019-12-06 01:22:10
I've tried multiple methods and tried some suggestions on this site, but how can I determine if a CoreData attribute "dueDate" is equal to "Today", I know NSDate is a specific time as well but I want the predicate to return if it is the same day/month/year regardless of what the time is in the day. Any suggestions? Stian Høiland This is what I came up with: - (NSPredicate *)matchAttribute:(NSString *)attributeName withDate:(NSDate *)date { NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:date];

Filter array in ios checking multiple properties

旧街凉风 提交于 2019-12-05 23:36:09
问题 I have an array of custom objects. The custom object look like this @interface User : NSObject @property(nonatomic, strong)NSString *user_Id; @property(nonatomic, strong)NSString *user_Name; @property(nonatomic, strong)NSString *user_UserName; @end I have to filter the array checking 2 properties.That is if I search a then it should get list of users filtered from array contains a in user_Name or user_Id .How can i achieve this? For a single property i know[user_Name] NSString

NSSet use predicate to return objects matching given class

一曲冷凌霜 提交于 2019-12-05 22:17:34
问题 Let's say I have an NSSet that contains a collection of objects of type id<Shape> . . . of which there are CircleShape, SquareShape, HexagonalShape instances put into it (not the real protocol or class names) . . is it possible to use a predicate or another single line of code to return all of the instances of CircleShape? 回答1: You can use a block-based predicate like this: NSSet *yourSet = ...; NSPredicate *pred = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary

iOS Compound Predicates

一个人想着一个人 提交于 2019-12-05 20:07:01
问题 I am writing an application that has a database of photos. Each photo has several tags associated with it and the application has a search page with a lot of toggles that allows users to search for photos based on only the tags that are of interest to them. Each of these tags have stored integer ID's because they correspond to an external database's IDs, so I am trying to look them up simply by ID. All of the ID fields are indexed. The problem arrises when the predicates that I am writing

An NSPredicate that can recursively traverse an object graph?

拜拜、爱过 提交于 2019-12-05 19:26:40
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 to go about this? Its been awhile since I asked this question, and I think I went in another direction

Dynamic searching in tableview in iOS

笑着哭i 提交于 2019-12-05 18:27:59
I've a tableview and text field where I've implemented search method. Right now, when I write some value in textfield and click search button, then it search in the tableview . But, I want it to be dynamic means the moment I start typing in textfield it should start searching without clicking any button . How can I do this? Just Connect this method on Editing Changed Event of your TextField . So, this method is called when you are changing its value. - (IBAction)txtValueChanged:(UITextField)sender { [self dynamicSearchInto:sender.text]; //From here, we are passing text of textField. } Here,