nspredicate

NSPredicate with a string matching beginning of words

我的梦境 提交于 2020-01-01 02:52:07
问题 This must be a duplicate. But with so many NSPredicate questions out there, I can't find the right one. I have a list of Core Data objects that contain a compositeName field. A name like 'Emily Blunt' could be in there. I want to search the list using an NSPredicate that will let me search for "Em" but also for "Bl" and then have this name show up in the fetched results. This must be super easy, but as you'd guess, I'm not seeing it. My dysfunctional attempt at an NSPredicate with a regular

“Whole word” search in a NSString through NSPredicate

99封情书 提交于 2020-01-01 01:13:16
问题 I would like to search if in the attribute description (an NSString instance) there is a given word. I tried with this predicate: [NSPredicate predicateWithFormat:@"description CONTAINS[cd] %@", theWord]; It works, but it finds also sub-words . For example, given theWord : Car it will mach also this description : A Christmas Carol Instead, I would like that my predicate will match only a , or christmas , or carol . (I'm using Core Data and NSFetchRequest.) 回答1: Something like this? NSString

CloudKit - NSPredicate for finding all records that contain specified CKReference in a reference list

余生长醉 提交于 2020-01-01 00:45:14
问题 I am working on a CloudKit backed app with a Users record type that has a "following" reference list attribute. I am trying to construct a query to get every user that is following a specified user (i.e. those users in which the specified user appears as an entry in the following reference list). I am currently trying to construct my NSPredicate for the CKQuery as such: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN following", [[CKReference alloc] initWithRecordID

What is the best way to build a complex NSCompoundPredicate?

北城以北 提交于 2019-12-31 22:38:49
问题 I need to build an NSPredicate with many pieces of data. For example in SQL I would do something like the following: SELECT * FROM TRANSACTIONS WHERE CATEGORY IN (categoryList) AND LOCATION IN (locationList) AND TYPE IN (typeList) AND NOTE contains[cd] "some text" AND DATE >= fromDate AND DATE <+ toDate I'm struggling with how to build this as an NSPredicate for use with Core Data. I've read the documentation... which only provides simplistic examples. If anybody can point me to a more

Core Data - filtering a To-Many Relationship using Predicates

余生颓废 提交于 2019-12-31 13:29:30
问题 I have the following two entities in my Core Data Model: Manufacture {name, ...other attributes} Product {name, .... other attributes} I have setup a One to Many Relationship: Manufacturer.manufactures <------>> Product.manufacturedBy I am trying to build a predicate to return all Products belonging to Manufacturers that match a search string. E.g. if there are two Manufacturers, "King Nut", and "Queen Nut" then a search on "Nut" should return all products made by both King Nut and Queen Nut.

onFormat string For NSPredicate

别说谁变了你拦得住时间么 提交于 2019-12-31 05:24:08
问题 I want to sort data with "id" key, how can I understand what is format string for NSPredicate format ? I have an 100 number post. My code : let objectIDs = posts.map{$0.id} let predicate = NSPredicate(format: "self IN %@", objectIDs) let sortByUserId = NSSortDescriptor(key: "id", ascending: true) I have an error with this description: can not parse "self IN %@" format string. Code for Parsing JSON Data: func postsFromJSONData(data : NSData, inContext context: NSManagedObjectContext) ->

NSPredicate omits special characters like á â á in filterContentForSearchText method

你。 提交于 2019-12-31 04:06:08
问题 I am developing an app with an UISearchBar and I need to filter some names with special characters like à, è, ê and so on.. but if I don't type the correct string with the special character it doesn't appear. Ex: If I am looking for cómodo word I can't find this word if I don't type exactly có How could I get that word without type that special characters? for example typing just co . This is my NSPredicate : NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.word

NSPredicate omits special characters like á â á in filterContentForSearchText method

早过忘川 提交于 2019-12-31 04:06:05
问题 I am developing an app with an UISearchBar and I need to filter some names with special characters like à, è, ê and so on.. but if I don't type the correct string with the special character it doesn't appear. Ex: If I am looking for cómodo word I can't find this word if I don't type exactly có How could I get that word without type that special characters? for example typing just co . This is my NSPredicate : NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.word

NSPredicate for exact match

試著忘記壹切 提交于 2019-12-31 03:53:08
问题 NSArray *arrData = [NSArray arrayWithObjects: @"cloud,country,plant", @"country,cloud,plant", @"country,plant,cloud", @"clouds,country,plant" ,@"country,clouds,plant", nil]; From above NSArray, I want objects which having a word "cloud" I tried below code NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(self beginswith %@ OR self contains[CD] %@)",@"cloud",@",cloud"]; NSArray *arrResult = [arrData filteredArrayUsingPredicate:predicate]; But it's giving all 5 objects in arrResult.

What is wrong in my nested SUBQUERY predicate?

淺唱寂寞╮ 提交于 2019-12-30 06:38:09
问题 I have the data model you can see below, and a nested SUBQUERY predicate, but in somehow it just not works. Any idea how to correct it? I figured out, this here down is working finally: [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $B, SUBQUERY($B.cs, $C, $C.ds.name != \"xxx\").@count > 0).@count > 0"]; 回答1: Ok, so here is the working solution: [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $B, SUBQUERY($B.cs, $C, $C.ds.name != \"xxx\").@count > 0).@count > 0"]; 来源: https://stackoverflow