nspredicate

Get sectionIndex titles based on contact name

核能气质少年 提交于 2019-12-12 04:58:18
问题 In my app I have a db with 50k+ contacts. To display them on list view, I need to calculate the index section titles to display them on the right side. However my logic is taking time around 3-6 seconds to prepare the datasource. -(NSArray *)getSectionTitleBasedOn:(NSString*)sortBy{ for (RealmContact *contact in contactSource){ if (contact.firstName.length>0) { if ([sortBy isEqualToString:@"FirstName"]) { NSString *firName= [contact.firstName stringByReplacingOccurrencesOfString:@" "

NSPredicate NSUnknownKeyException - Swift 4.0

[亡魂溺海] 提交于 2019-12-12 04:39:13
问题 I have my current code as listed below: class ViewController:UIViewController{ ovveride func viewDidLoad(){ filterData() } func filterData(){ var usersArray = [User(name:"John",userId:1),User(name:"Ed",userId:2),User(name:"Ron",userId:3)] let filteredData = (userArray as NSArray).filtered(using:NSPredicate(format: "userId=1")) } } The above code throws throws the following Exception ( NSUnknownKeyException ): The Object Type ' [<ViewController.User 0x6000000afa20> valueForUndefinedKey:] ':

Core Data NSPredicate “deleted == NO” does not work as expected

流过昼夜 提交于 2019-12-12 03:55:11
问题 I am using UIManagedDocument with Parent Child context. In my child context I do the following Code 1 NSSet *results = [self.event.memberships filteredSetUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { return ([[evaluatedObject deleted] boolValue] == NO); }]]; Above code returns the expected results (only Not deleted members for the event). Code 2 But this code does not. It fetches all records. NSPredicate *predicate = [NSPredicate

why nspredicate not working

走远了吗. 提交于 2019-12-12 02:57:10
问题 - (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != nil) { return _fetchedResultsController; } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"KeyRefEntity" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; [fetchRequest setFetchBatchSize:20]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"time" ascending:NO];

Sort Descriptor Not functioning correctly or consistently

女生的网名这么多〃 提交于 2019-12-12 02:49:05
问题 I am using a sort descriptor and a set predicate between 4 entities. entity one: workoutType Relationship workouts 1 to many entity two: workoutSet Relationship days 1 to many entity three: workoutDay relationship exercises 1 to many entity four: workoutExercise Inverses are also set. The problem i am receiving is that the sortDescriptor is working correctly behind the scenes, but what is displayed is incorrect. For example in my workoutDay entity i have attribute dayName of string type.

Setting up a CoreData regular expression predicate for a comma-separated list

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:35:08
问题 I'm beating my head against a wall trying to get a regular expression function to work with a CoreData fetch. I have an attribute named maps on an NSManagedObject subclass that I'm trying to filter by. This maps attribute is a string with a list of id values like so: 1,10,12,8 Here's how my predicate is being constructed: NSString *format = [NSString stringWithFormat: @"(maps matches '.*\\b%@\\b.*')", _map.mapID]; NSPredicate *predicate = [NSPredicate predicateWithFormat:format]; [request

Using NSPredicate get only values of a particular key from an array of dictionaries

大兔子大兔子 提交于 2019-12-12 02:23:55
问题 I do not know the values. I only know the key. arrTripCat : ( { tripcategory = "general_tourism"; }, { tripcategory = nightlife; }, { tripcategory = "art_museums"; }, { tripcategory = nightlife; }, { tripcategory = architecture; }, { tripcategory = nightlife; } ); The NSPredicate I tried : NSArray *arrTripCat = [NSArray arrayWithArray:[self.dictSearchResult objectForKey:@"TripCategories"]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF.@allKeys contains[cd] %@",@

Core Data many-to-many predicate

北城余情 提交于 2019-12-12 01:56:14
问题 I have two entities which are related by a many-to-many relationship: Database <<----->> Category In other words, a database can have many categories and a category can be associated with many databases. I need an NSPredicate that will return all Category objects associated with a given database object. Any help would be appreciated. 回答1: You don't need a predicate. Given that you have a relationship called categories that is the to-many relationship to your Category entities, then NSSet

CoreData: many-to-many relationship

亡梦爱人 提交于 2019-12-12 01:24:55
问题 I have 2 objects, with many to many relationships. Here's my code: + (NSSet *)activitiesSetForMember:(Members *)member inManagedObjectContext:(NSManagedObjectContext *)context{ NSSet *activitiesSet = nil; NSFetchRequest *request = [[NSFetchRequest alloc] init]; request.entity = [NSEntityDescription entityForName:@"CompanyActivity" inManagedObjectContext:context]; request.predicate = [NSPredicate predicateWithFormat:@"hasMembers contains %@", member]; NSError *error = nil; activitiesSet = [

Problem while using NSPredicate

情到浓时终转凉″ 提交于 2019-12-12 01:24:26
问题 Sql query: select * from test_mart where replace(replace(replace(replace(replace(replace(lower(name),'+'),'_'),'the '),' the'),'a '),' a')='tariq' I can fire following query very easy, if I have to use simply Sqlite... but In current project I am using Core Data so not familiar about NSPredicate much. The functionality talks about removing all BUT alphanumeric characters, which means removing special characters. The characters that should be valid in the comparison would be