nsfetchrequest

NSFetchRequest returning nothing

自作多情 提交于 2019-12-06 01:34:38
Can anyone spot why this isn't returning any ManagedObjects? I'm trying to add to the ATNSManagedObject+EasyFetching class the following, but the fetch result returns nothing. If I fetch these outside of the EasyFetch class I have 100+ objects so I know it isn't CoreData being empty. + (void)deleteAllObjectsInContext; { NSManagedObjectContext *context = [NSManagedObjectContext defaultContext]; NSEntityDescription *entity = [self entityDescriptionInContext:context]; NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; [request setEntity:entity]; //[request

core data and paging

我的未来我决定 提交于 2019-12-05 17:24:20
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. 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.com/questions/3067543/core-data-and-paging

UITableView not updating DataSource after change to NSFetchedResultsController

送分小仙女□ 提交于 2019-12-05 11:41:21
I have an UITableView populated by a NSFetchedResultsController . The initial fetch works fine. I can add, remove, modify, etc with zero problems.. But I want to add user-defined sorting to the table. I am doing this by changing the NSFetchedResultsController to use a different sortDescriptor set, and a different sectionNameKeyPath . Here is the code where I change the fetch: -(void)changeFetchData { fetchedResultsController = nil; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Object" inManagedObjectContext

NSPredicate that filters out subclass results

浪尽此生 提交于 2019-12-05 11:23:38
I have two classes, Company and MyCompany. MyCompany is a subclass of Company, and Company is a subclass of NSManagedObject. I am trying to write a predicate for an NSFetchRequest that will return results of the class Company, but filter out MyCompany objects. I have tried the following (suggested from here https://stackoverflow.com/a/8065935/472344 ): NSPredicate *predicate = [NSPredicate predicateWithFormat:@"class != %@",NSStringFromClass([myCompany class])]; But I get an error: 'keypath class not found in entity <NSSQLEntity CKCompany id=1>' I also tried (suggested from here https:/

NSFetchRequest without sort descriptors

谁说胖子不能爱 提交于 2019-12-05 08:02:30
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). 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 care about the date something was created, you should add a dateCreated attribute to your data object. Then,

Is it possible to sort by subclasses in an `NSFetchRequest` without adding additional attributes?

一世执手 提交于 2019-12-05 06:55:43
I want to group the results of a NSFetchRequest by entity. The entities all share the same abstract parent. For example: animal | |-cat | |-dog The NSFetchRequest has includesSubentities set TRUE and entity set to animal . It is possible to set sectionNameKeyPath of NSFetchedResultsController to entity.name but it is not possible to do the same with the sortDescriptors of the NSFetchRequest due to the fact that the sortDescriptors are applied to the stored attributes (i.e. data in the database, not methods on the classes). Therefore the only way to group by entity type is to add an attribute

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

烈酒焚心 提交于 2019-12-05 05:18:19
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 the request should return dictionaries. [request setResultType:NSDictionaryResultType]; // Create an

Core Data NSPredicate fetch on entity relationship using in clause

隐身守侯 提交于 2019-12-05 04:04:17
I would like to be able to search the relationship of an entity using an IN clause. I have the following setup: I would like to send over an array of nicknames and find all Persons associated with those nicknames. //array of names to find let nameArray: [String] = ["Tom", "Tommy", "Thomas"] // find all Persons who have a nickname associated with that person let predicate = NSPredicate(format: "ANY Person.nickName in %@",nameArray) var fetch = NSFetchRequest(entityName: "Person") fetch.predicate = predicate var fetchError : NSError? = nil // executes fetch let results = context?

Case Insensitive Compare with Core Data and Swift

时光毁灭记忆、已成空白 提交于 2019-12-05 02:49:35
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? The selector is caseInsensitiveCompare: , with the colon, and you can use it with Core Data. The colon is there

Swift 3 - NSFetchRequest Distinct Results

99封情书 提交于 2019-12-05 01:27:10
Any help appreciated. Xcode auto updated to 8... I am Targeting IOS 9.3 Have all of the code converted across but one thing is now breaking, I have tried various suggestions in similar questions! My fetch request that was previously working is now breaking. My goal is to get a distinct list. The app crashes on the line: let results = try context.fetch(fetchRequest) With the error described in the console as: Could not cast value of type 'NSKnownKeysDictionary1' (0x10fd29328) to 'MyApp.BodyType' (0x10eebc820). Here is the function func getBodyTypes() { let context = ad.managedObjectContext let