nsfetchrequest

How to sort based on a calculated value from multiple Core Data attributes

♀尐吖头ヾ 提交于 2019-12-08 00:38:51
问题 I'm trying to create a sort descriptor, for a core data fetch request, that will fetch objects that are ordered by a calculated value (e.g., the sum of two or more attributes). Is this possible? Thanks in advance. 回答1: From the "Core Data Programming Guide": You cannot fetch using a predicate based on transient properties (although you can use transient properties to filter in memory yourself). ... To summarize, though, if you execute a fetch directly, you should typically not add Objective-C

I got fault when I fetched my data from NSManagedObjectContext

点点圈 提交于 2019-12-07 14:48:22
问题 I run my app and then fetched my data. Data is ok. When I run second time I got fault for my old values. What is wrong? - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" inManagedObjectContext:[self managedObjectContext]]; for (int i =0; i<2; i++) { Test *test = [[[Test alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]]

NSFetchedResultsController fetch request - updating predicate and UITableView

两盒软妹~` 提交于 2019-12-07 13:54:49
问题 In my iPhone Core Data app I have it configured in a master-detail view setup. The master view is a UITableView that lists objects of the List entity. The List entity has a to-many relationship with the Task entity (called "tasks"), and the Task entity has an inverse to-one relationship with List called "list". When a List object is selected in the master view, I want the detail view (another UITableView) to list the Task objects that correspond to that List object. What I've done so far is

NSFetchRequest Core Data Swift 3 Backward compatibility

走远了吗. 提交于 2019-12-07 11:02:52
问题 I have converted my code in swift 3. I am using core data in my application. As you know, NSFetchRequest has been changed. In swift 2 it was: let request = NSFetchRequest(entityName: "UnsyncedTask") In swift 3: let request:NSFetchRequest<NSFetchRequestResult> = UnsyncedTask.fetchRequest() My question is, It only supports ios 10. How can I make it backward ios compatible? I want NSFetchRequest which supports ios 9, ios 10 with swift 3. 回答1: NSFetchRequest(entityName:) is still available in

core data and paging

喜你入骨 提交于 2019-12-07 07:44:41
问题 I have a database of 50,000 records. I'm using core data to fetch records from a search. A search could return 1000 records easily. What is needed to page through these records using core data and uitableview? I would like to show 100 records at a time and have 'load more' button after viewing 100 records. 回答1: Take a look at the NSFetchRequest and its controls over batches. You can set the batch size and the offset which will allow you to "page" through the data. 来源: https://stackoverflow

fetchRequestFromTemplateWithName variables

一世执手 提交于 2019-12-07 05:57:26
I'm using Xcode 4.2.1 and trying to use a variable. I understand in xcode 4 you need to set the variable with $variable . I have in Xcode for my fetch request the variable as $currDate and my code as NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"YYYYMMdd"]; NSDate *currDate = [NSDate date]; NSString *currDateString = [dateFormatter stringFromDate:currDate]; NSError *error; NSFetchRequest *fetchRequest = [[[DataManager sharedInstance] objectModel] fetchRequestFromTemplateWithName:@"fetchAppointmentsByDate" substitutionVariables:[NSDictionary

NSFetchRequest without sort descriptors

混江龙づ霸主 提交于 2019-12-07 03:32:29
问题 We cannot use NSFetchRequest without providing NSSortDescriptor(s). All i want to do is fetch the results and show them in the order in which they were created. Is there a built-in way to do that?, or will i have to create a new "auto-increment" field? (which goes against everything CoreData stands for, in my opinion). 回答1: Core Data does not guarantee anything about order. You don't have to make an "auto-increment" field; however, you can make an appropriate attribute. Since you obviously

Can I set transient properties to fetch?

点点圈 提交于 2019-12-07 01:30:49
问题 I want to create NSFetchRequest and set properties to fetch like this: request.propertiesToFetch = @[@"a", @"b", @"c"]; where a and b are stored in Core Data database, and c is transient. executeFetchRequest: fires an error Invalid keypath c passed to setPropertiesToFetch: . But if I uncheck transient-checkbox for property c everything will work fine. So is it really impossible to fetch transient properties or I'm doing something wrong? 回答1: Yes, it is really impossible. You can't fetch them

Core Data: trying to find minimum date for an attribute in an entity

会有一股神秘感。 提交于 2019-12-06 22:21:08
问题 I'm trying to find the oldest date in a particular attribute in Core Data. I've found an example in the Core Data Programming Guide that purports to do exactly that, but keep getting an unrecognized selected error when I run it. My code (with only minimal changes from the Apple Example): NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session" inManagedObjectContext: ctx]; [request setEntity:entity]; // Specify that

Case Insensitive Compare with Core Data and Swift

时光毁灭记忆、已成空白 提交于 2019-12-06 21:23:00
问题 The following code doesn't work: let sortDescriptor = NSSortDescriptor(key: "name", ascending: true, selector:"caseInsensitiveCompare") And gives the following error: 'NSInvalidArgumentException', reason: 'unsupported NSSortDescriptor selector: caseInsensitiveCompare' Seemed to work fine in Objective-C. Any ideas on why this might be? Edit: seems like this may not be possible with Core Data/SQLite. In that case, is the best option to get the array and sort it in code afterwards? 回答1: The