nsfetchrequest

NSSortdescriptor ineffective on fetch result from NSManagedContext

放肆的年华 提交于 2019-12-19 21:16:52
问题 I'm trying to sort my NSFetchRequest result using a NSSortdescriptor using a key pointing to a NSDate value. My fetch results come out totally random for no clear reason. The NSManagedObjectContext I'm using is updated with a save from a nested child context created on a subclass of NSOperation. I know all this is done successfully because I can get all the data needed from the parent (main) context. Fetching from it just wont sort on date! Strange thing is; predicates for selecting the

Swift Core Data - Request with distinct results

假如想象 提交于 2019-12-18 17:31:45
问题 how I can call es request with distinct values in swift? This is my code: let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate let context: NSManagedObjectContext = appDelegate.managedObjectContext let request = NSFetchRequest(entityName: "MedicalData") request.propertiesToFetch = NSArray(object: "docID") request.returnsObjectsAsFaults = false request.returnsDistinctResults = true var results:NSArray = context.executeFetchRequest(request, error: nil) for

NSDictionaryResultType expression not taking into account newly inserted objects

时光毁灭记忆、已成空白 提交于 2019-12-18 06:43:39
问题 I want the maximum value of a field in core data so I have set up the following request: // Create fetch NSFetchRequest *fetch = [[NSFetchRequest alloc] init]; [fetch setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:context]]; [fetch setResultType:NSDictionaryResultType]; // Expression for Max ID NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"myNumbericID"]; NSExpression *minExpression = [NSExpression expressionForFunction:@"max:"

How do I use an SQL GROUP BY and SUM functions in a IOS CORE-DATA request in SWIFT?

我怕爱的太早我们不能终老 提交于 2019-12-17 19:37:00
问题 I have a table (Transactions) which holds records containing the Account_name and an Amount for the transaction. I would like to calculate the total for all transactions per account which start with 'Private' and for which the transaction amount is > 1000. I would like to get the accounts sorted by name, in a descending order. So the SQL request would be something like this : SELECT Account_name, SUM(Amount) FROM Transactions WHERE Account_name like 'Private%' and Amount > 1000 GROUP BY

CoreData get distinct values of Attribute

时间秒杀一切 提交于 2019-12-17 17:26:48
问题 I'm trying to setup my NSFetchRequest to core data to retrieve the unique values for a specific attribute in an entity. i.e. an entity with the following information: name | rate | factor | _______|______|________| John | 3.2 | 4 | Betty | 5.5 | 7 | Betty | 2.1 | 2 | Betty | 3.1 | 2 | Edward | 4.5 | 5 | John | 2.3 | 4 | How would i set up the request to return an array with just: John, Betty, Edward? 回答1: You should use the backing store to help you get distinct records. If you want to get an

Core data, how to get NSManagedObject's ObjectId when NSFetchRequest returns NSDictionaryResultType?

戏子无情 提交于 2019-12-17 17:26:43
问题 I have an NSFetchRequest which is returning the objects' properties in an NSDictionaryResultType . Is it possible to also get the objects' ObjectId within this dictionary? Otherwise I will need to run the query with a return type of NSManagedObjectResultType which is much slower for a large number of returned items. 回答1: Yes you can, using the very nifty but badly-documented NSExpressionDescription class. You need to add a properly-configured NSExpressionDescription object to the array of

NSFetchRequest and predicateWithBlock

眉间皱痕 提交于 2019-12-17 07:23:55
问题 I am playing with an app that uses Core Data and NSManagedObjects to populate a UITableView. There is only one class in my application, called Event . I have created the following custom instance method on Event : - (BOOL)isExpired { return ([[self.endOn dateAtEndOfDay] timeIntervalSinceNow] < 0); } I would like to limit the UITableView that displays Event objects to only the Events that are expired - that is, where isExpired returns YES . I have tried to do this by adding an NSPredicate to

Core Data Table Relationship and Fetchrequest

半腔热情 提交于 2019-12-14 00:10:12
问题 I am developing one iPad application using storyboard and core data.I have no good idea about core data.I have 2 tables names A and B. Table a have 2 fields with names datacode and price.In table B there are two fields with names itemcode and text.Table A have set limit. Table A datacode price p1 10 m1 17 p0 28 m3 20 w4 12 Table B itemcode text p0 car p1 bus m2 pen m1 ball p0 ban r1 book m3 pencil n1 tv w4 radio The values in itemcode in tableB is the data code in the table A + some other

Filtering a CoreData FetchRequest

守給你的承諾、 提交于 2019-12-13 07:16:42
问题 I am having a brain meltdown trying to filter a fetchRequest. I'm able to get the full details of every record of the entity, but I only want the details on the record at the current indexPath. This is where my code is at present: -(void) fetchStuff { NSLog(@"%s", __FUNCTION__); NSError *error = nil; NSManagedObjectContext *context = [self managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *woodgie = [NSEntityDescription entityForName:@

Completion block/callback on FetchRequest completion

梦想的初衷 提交于 2019-12-13 06:34:17
问题 I have a FetchRequest in my model class named ContentManager . It fetches quite a lot of data, so the screen is blank until it's completion. In the ViewController that displays the fetched results, I would like to show a loading indicator, so I would like to get a callback when the FetchRequest has completed and pass that to the ViewController to stop the loading indicator. Is this possible? Here is the FetchRequest from the ContentManager class: - (NSArray*)recipesForMagazine {