nspredicate

Swift combining predicates LogicalType AND OR

懵懂的女人 提交于 2019-12-12 18:07:58
问题 How can i combine a mix AND OR condition in Swift predicate. I have a following query Select * from tblTemp where dept == 1 && (subdept == 11 || subdept == 12) I can write two predicate with same operator but don't know how to combine them let deptPredicate = NSPredicate(format: "dept == %@", 1) let subdeptPredicate1 = NSPredicate(format: "subdept = %@", 11) let subdeptPredicate2 = NSPredicate(format: "subdept = %@", 12) let andPredicate = NSCompoundPredicate(type: NSCompoundPredicate

how to find the index position of the ARRAY Where NSPredicate pick the value. I use filteredArrayUsingPredicate as filter

半腔热情 提交于 2019-12-12 13:27:00
问题 here is an example to filter the array which has start time and end time according to the current time. this is working fine: QUESTION : but here I want to know the index position of the collectionArr where predicate pick the value. NSDate* currentDate = [NSDate date]; NSDateFormatter *_formatter = [[[NSDateFormatter alloc] init] autorelease]; [_formatter setLocale:[NSLocale currentLocale]]; [_formatter setDateFormat:@"yyyy-MM-dd hh:mm a"]; NSString *_date=[_formatter stringFromDate

How to remove all objects with the same property value but one in NSMutableArray

有些话、适合烂在心里 提交于 2019-12-12 13:15:58
问题 I have a history object with a url string property and title. I want to search all the history for objects with the url containing a search string, then remove all duplicates. Example: I have an array of history objects and 20 of them are all "https://www.google.com" and 4 are "https://www.google.com/#q=search", I want to get an array back with only one object with the url value of "https://www.google.com" and one url value of "https://www.google.com/#q=search" Here is my current code that

nspredicate multiple items from an array

谁都会走 提交于 2019-12-12 10:55:47
问题 how to use NSPredicate to satisfy multiple conditions NSEntityDescription *entity = [NSEntityDescription entityForName:@"MessageData" inManagedObjectContext:managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:entity]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"msg_id = %@",msg_id]; [fetchRequest setPredicate:predicate]; i need to fetch objects in which msg_id = values in a array 回答1: You can do "msg_id IN %@", array .

Realm: predicate returning LazyFilterCollection - how to convert to Results<T>?

倖福魔咒の 提交于 2019-12-12 10:44:39
问题 I'm filtering my database query with NSPredicate s directly on the database, but then I would like to go further and filter the returned values ( Results<T> ) with a custom predicate: elements.filter { (element) -> Bool in return ... } this one returns a LazyFilterBidirectionalCollection - how can I use this and get the Results again? 回答1: We're tracking adding support for block-based predicates in GitHub issue #2138. This will allow you to perform custom filtering outside of that supported

Displaying Core Data: If attribute has same name display once

北慕城南 提交于 2019-12-12 09:58:56
问题 I have viewed numerous predicate questions, I have read the docs and nothing seems to be jumping out as an answer my problem. I have a Core Data entity named Materials and I have the Attributes category , subcategory and description . I have three UITableViewControllers and in each I want to use a predicate to display as follows: TableViewController 1: Only the categories (no repeating of category names) Select a category and go to TableViewController 2. TableViewController 2: Display

How to Predicate through Nested Arrays with Keys

心不动则不痛 提交于 2019-12-12 08:17:36
问题 I have an array called self.eventsArray which looks like this: [ { "artist": [ { "artist_name": "Dillon Francis", "name": "Dillon Francis", }, { "artist_name": "Major Lazer", "name": "Major Lazer", }, { "artist_name": "Flosstradamus ", "name": "Flosstradamus", } ], "name": "Mad Decent Block Party NYC", }, { "artist": [ { "artist_name": "Ryan Raddon", "name": "Kaskade", } ], "name": "Kaskade Atmosphere Tour NYC", }, ] I have been trying to filter it by using NSPredicate two times. When the

Core Data Transformable attributes NOT working with NSPredicate

☆樱花仙子☆ 提交于 2019-12-12 07:57:02
问题 I often use Transformable for Core Data attributes , so I can change them later. However, it seems like, if I want to use NSPredicate to find a NSManagedObject , using "uniqueKey == %@" , or "uniqueKey MATCHES[cd] %@" , it's not working as it should. It always misses matching objects, until I change the attributes of the uniqueKey of the matching object to have specific class like NSString , or NSNumber . Can someone explain the limitation of using NSPredicate with Transformable attributes?

How to filter a multi-dimensional array

筅森魡賤 提交于 2019-12-12 05:43:12
问题 I have the following multi-dimensional array (stripped and reduced for clarity) [ { "type": "type1", "docs": [ { "language": "EN" }, { "language": "DE" }, { "language": "EN" } ] }, { "type": "type2", "docs": [ { "language": "EN" } ] }, { "type": "type3", "docs": [ { "language": "FR" }, { "language": "DE" }, { "language": "DE" } ] } ] I want to filter it, so only docs objects with a language of DE are shown. In other words, I need this: [ { "type": "type1", "docs": [ { "language": "DE" } ] },

hyphen in NSDictionary key

天涯浪子 提交于 2019-12-12 05:38:51
问题 I've been working this for a few days now with no luck.. I am trying to parse a collection of key/value pairs from an NSDicitonary but it seems to be very sensitive to a hyphen in the key name. Below is an example of the data.. If I try to access any of the fields with a hyphen using the code below I get the following error: unrecognized selector sent to instance Any suggestions? NSString *param = [[NSString alloc] initWithFormat:@" url-name like %@",url ]; NSPredicate *predicate =