nspredicate

Fetched Properties - Predicate

核能气质少年 提交于 2019-11-30 20:18:08
问题 I have a question about using fetched properties inside a NSPredicate (see below 'My question'). It's not about the predicate to get the fetched property. For clarification and for others, which may also face this problem I tried to make a small sample project. SAMPLE PROJECT The need to use Fetched Properties came, because my app was rejected because of violating the iOS Data Storage Guidelines. In QA1719 they write: Apps should avoid mingling app data and user data in the same file. I think

NSPredicate and CoreData - decide if a Date attribute is “today” (or between last night 12am to tonight 12am) on iOS

只愿长相守 提交于 2019-11-30 19:12:28
I'm using a NSFetchedResultsController and a UITableViewController to populate a UITableView from a CoreData database. I have a NSDate object saved into this Date attribute labeled "startTime". Then I'm trying to only pull todays's data by using a NSPredicate that looks like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate == %@", todaysDate]; I'm getting zero results. I understand this because a NSDate object just hold the number of seconds or milliseconds or whatever since Jan 1 1970 right? So comparing 1111111111111 and 1111111111112, while on the same day, are

Multiple NSPredicate

半世苍凉 提交于 2019-11-30 17:21:07
I'm trying to prepare multiple search in my CoreData entity Recipes . There are parameters by which I would like to prepare fetch. Recipes attributes: @property (nonatomic, retain) NSNumber * difficulty; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSNumber * code; //like identifier @property (nonatomic, retain) NSNumber * prepTime; Ingredients is a separate entity with the list of ingredients. Join entity contains ingredientCode , recipeCode , count . getArrayOfJoinDataWithIngredients fetches join entity and returns NSArray of codes of recipes which contains

Remove objects using NSPredicate

社会主义新天地 提交于 2019-11-30 16:29:14
I have the folloving dictionary which has many sub dictionaries. How can I remove objects where isChanged = 1 from parent dictionary using NSPredicate ? { "0_496447097042228" = { cellHeight = 437; isChanged = 1; }; "100000019882803_193629104095337" = { cellHeight = 145; isChanged = 0; }; "100002140902243_561833243831980" = { cellHeight = 114; isChanged = 1; }; "100004324964792_129813607172804" = { cellHeight = 112; isChanged = 0; }; "100004324964792_129818217172343" = { cellHeight = 127; isChanged = 0; }; "100004324964792_129835247170640" = { cellHeight = 127; isChanged = 1; }; } As a simple

NSPredicate- For finding events that occur between a certain date range

本小妞迷上赌 提交于 2019-11-30 16:09:36
This is a little more complicated then just NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate >= %@ AND endDate <= %@", startDay,endDay]; I'm building a calendar app and I need to pull events out of my core data store that occur on a given day. However, it's possible for an event to start/end on a different day then the day I'm trying to display, e.g. My Date Range (Start = 2011-12-02 00:00:00 to End = 2011-12-02 23:59:59) An Event (Start = 2011-12-01 23:00:00 to End = 2011-12-02 05:00:00) How can I write a predicate to determine if that event falls in that date range. Keep

Filtering array of dictionaries in Swift

纵饮孤独 提交于 2019-11-30 16:02:21
I have An Array With Dictionaries example : ( { Email = "kate-bell@mac.com"; Name = "Kate Bell"; Number = "(555) 564-8583"; }, { Email = "d-higgins@mac.com"; Name = "Daniel Higgins"; Number = "555-478-7672"; } ) And i want to filter this dictionary according to Key "Name" func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { let predicate = NSPredicate(format:"Name == %@", searchText) let filteredArray = (arrContact as NSMutableArray).filteredArrayUsingPredicate(predicate) print(filteredArray) if(filteredArray.count == 0){ searchActive = false; } else { searchActive = true

Limit the results of a Swift array filter to X for performance

柔情痞子 提交于 2019-11-30 15:57:02
问题 I have about 2000 elements in my array, and when it is filtered, I would like to end the filtering as soon as I have 5 elements in my filtered array. Currently it is: providerArray.filter({($0.lowercased().range(of:((row.value as? String)?.lowercased())!) != nil)}) which can return up to 2000 results which is a waste of processing, and time. To be more clear, I need a solution that is equivalent to limiting the filter results like I can with coreData fetches [request setFetchLimit:5]; 回答1:

Limit the results of a Swift array filter to X for performance

ぃ、小莉子 提交于 2019-11-30 15:40:28
I have about 2000 elements in my array, and when it is filtered, I would like to end the filtering as soon as I have 5 elements in my filtered array. Currently it is: providerArray.filter({($0.lowercased().range(of:((row.value as? String)?.lowercased())!) != nil)}) which can return up to 2000 results which is a waste of processing, and time. To be more clear, I need a solution that is equivalent to limiting the filter results like I can with coreData fetches [request setFetchLimit:5]; The fastest solution in terms of execution time seems to be an explicit loop which adds matching elements

NSPredicate 'The left hand side for an ALL or ANY operator must be either an NSArray or NSSet'

▼魔方 西西 提交于 2019-11-30 15:13:22
Not totally sure why this isn't working now, i thought it had been working previously. Does anyone see an issue with this FetchRequest construction? - (NSArray *)entriesForDate:(NSDate *)date { NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY addedOn.unique like %@", [T3Utility identifierForDate:date]]; request.predicate = predicate; NSError *error = nil; NSArray *matches = [self.database.managedObjectContext executeFetchRequest:request error:&error]; return matches; } Again, i'm 99% sure that this

Filtering array of dictionaries in Swift

南楼画角 提交于 2019-11-30 14:20:44
问题 I have An Array With Dictionaries example : ( { Email = "kate-bell@mac.com"; Name = "Kate Bell"; Number = "(555) 564-8583"; }, { Email = "d-higgins@mac.com"; Name = "Daniel Higgins"; Number = "555-478-7672"; } ) And i want to filter this dictionary according to Key "Name" func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { let predicate = NSPredicate(format:"Name == %@", searchText) let filteredArray = (arrContact as NSMutableArray).filteredArrayUsingPredicate(predicate