nspredicate

How to filter array with NSPredicate for combination of words

空扰寡人 提交于 2019-12-05 18:01:35
[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 ? Maybe like this: [filteredArray filterUsingPredicate: [NSPredicate predicateWithFormat: @"self

How to specify range with NSPredicate in Objective C

岁酱吖の 提交于 2019-12-05 17:58:30
I want to query sqllite table by specifying a range. So it's like give me all records whose id column between 3000 and 3010. I tried what Apple recommends, but it didn't work. Here is what I tried and failed. NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]]; I have 2 strings called start and end. I updated Apple's example as following. NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"%@ BETWEEN %@", columnName, @[start,end]]; When I executeFetchRequest with the above predicate I get 0 records even though the table has

Parsing and changing NSPredicate

ε祈祈猫儿з 提交于 2019-12-05 17:37:26
I have to migrate data from a previous app version to a new version. This also affects some predicates ( NSPredicate instances) that were saved by users, which means that I have to change them programmatically. Currently I try to parse the string I get with [NSPredicate predicateFormat] and change some expressions manually. For instance oldKeyPath == "something" to newKeyPath == "something" . But it feels like a hack and I'm curious if there is a better way? I read Apple's documentations about programming with NSPredicate and NSExpression. There are plenty methods to compose NSPredicate

How to join two strings for NSPredicate, ie firstname and lastname

有些话、适合烂在心里 提交于 2019-12-05 12:26:07
问题 I have a Person Object which has two NSString properties; firstName and lastName . I'm currently using an NSPredicate like so: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName contains[cd] %@) OR (lastName contains[cd] %@)", searchText, searchText]; So, for example, say I'm searching for the name "John Smith" . In my search bar if I type "Joh" , then John Smith will appear as an option. This is good and fine, but if I type in "John Sm" it will go blank. How can I join

NSPredicate that filters out subclass results

浪尽此生 提交于 2019-12-05 11:23:38
I have two classes, Company and MyCompany. MyCompany is a subclass of Company, and Company is a subclass of NSManagedObject. I am trying to write a predicate for an NSFetchRequest that will return results of the class Company, but filter out MyCompany objects. I have tried the following (suggested from here https://stackoverflow.com/a/8065935/472344 ): NSPredicate *predicate = [NSPredicate predicateWithFormat:@"class != %@",NSStringFromClass([myCompany class])]; But I get an error: 'keypath class not found in entity <NSSQLEntity CKCompany id=1>' I also tried (suggested from here https:/

A reverse kind of string compare using NSPredicate

痴心易碎 提交于 2019-12-05 10:42:41
I've been searching for this answer all over internet but so far no luck. So I need to consult the smart and nice people here. This is my first time asking a question here, so I hope I am doing this right and not repeating the question. For all the examples I saw, it's the search string that is a substring of what's stored in the Core Data. On the other hand, I want to achieve the following: The strings stored in core data are actually sub-strings. I want to do a search by getting all core data rows that have substrings belong to the provided search string. For ex: In core data, I have "AB",

Subclassing NSPredicate to add operator

为君一笑 提交于 2019-12-05 08:26:09
Cocoa defines predicate classes ( NSPredicate , NSExpression , etc.) which "provide a general means of specifying queries in Cocoa" Predicate Programming . This set of classes describes what I need but with one little short-coming : I'd like additional operators. NSComparisonPredicate already handles 14 operators ( NSPredicateOperatorType ) but I would like to add, say, temporal operators... or operators to represent things such as: " variable has at least n entries " (binary operator) " variable has value for, at most, n consecutive days " (ternary operator) Obviously, I would need to

UISearchBar performance issue with Core Data

允我心安 提交于 2019-12-05 06:58:23
问题 When I use UISearchBar and write something as a search string this whole searching thing gets a little laggy . My guess is that I'm messing UI stuff and Core Data in the main thread but I might be wrong. What is more, I use one entity for all of this stuff so there are no relations etc. there are 3321 objects in this table and this app is consuming approximately 12 to 14 MB of RAM what you can see on the screenshot below: I thought that it'll be more efficent as 3321 objects isn't so much.

Why “NOT IN” does not work in this NSPredicate?

别等时光非礼了梦想. 提交于 2019-12-05 05:24:54
A . b and B . a are inverse to-many relationships. Why does this predicate for A work: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", bObject.a]; while this one does not: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT %@ IN b", bObject]; I think both predicates should give the same result — the collection of A s that have no relation with bObject via a<-->b . But in fact, the first one gives the correct collection while the second one not. Update: Here is a sample project wherein A . b is embodied by Account . filtered_clients and B . a is

Core Data NSPredicate fetch on entity relationship using in clause

隐身守侯 提交于 2019-12-05 04:04:17
I would like to be able to search the relationship of an entity using an IN clause. I have the following setup: I would like to send over an array of nicknames and find all Persons associated with those nicknames. //array of names to find let nameArray: [String] = ["Tom", "Tommy", "Thomas"] // find all Persons who have a nickname associated with that person let predicate = NSPredicate(format: "ANY Person.nickName in %@",nameArray) var fetch = NSFetchRequest(entityName: "Person") fetch.predicate = predicate var fetchError : NSError? = nil // executes fetch let results = context?