core-data

NSManagedObject's hasChanges is true while changedValues is empty

流过昼夜 提交于 2020-06-10 02:53:23
问题 I am trying to observe individual NSManagedObject changes on NSManagedObjectContextWillSaveNotification : - (void)managedObjectContextWillSave:(NSNotification *)notification { for (NSManagedObject * object in self.mutableObservedManagedObjects) { if (object.hasChanges) { [self managedObjectWasUpdated:object]; } } } The problem is that hasChanges is true while object.changedValues is empty, thus wrongly (?) triggering managedObjectWasUpdated: . I'm trying to understand why this is the case and

How do I properly use Codable, CoreData and NSSet relationships?

被刻印的时光 ゝ 提交于 2020-06-09 04:47:21
问题 I'm following this tutorial to implement CoreData with Codable . Everything seems to be going great however I cannot figure out how to encode my list of photo objects. You can see my data structure in the image below and view my current code. When I try to decode the photos objects in the Pin class as below I get the error: Referencing instance method 'encode(_:forKey:)' on 'Optional' requires that 'NSSet' conform to 'Encodable' Photo+CoreDataClass.swift import Foundation import CoreData

Setting Up CoreData with SceneDelegate - unknown identifier 'window' error - iOS 13 onwards

微笑、不失礼 提交于 2020-05-29 11:57:57
问题 I was trying to use the official apple documentation for Core Data. Found here. I also ran into a question which was related to my issue, right here on stack. I ran into an issue where, it kept saying that 'window' is not available in the context of AppDelegate. This is the very basic step as per the official documentation. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if let rootVC = window?

Sort NSPredicate with in clausule with array's order

时间秒杀一切 提交于 2020-05-29 07:54:28
问题 I have a NSPredicate that does a search of id within an NSArray of ids, something like ('id in %@',array) Is there a way to get the resultset of that fetch sorted with the same array's order? The code I have now is +(NSArray*) findIn:(NSArray*)identifiers{ if(identifiers == nil) return nil; NSPredicate *searchFilter = [NSPredicate predicateWithFormat:@"id IN %@", identifiers]; NSArray *fetchedObjects = [GSBaseModel setupFetch:[[self class] managedObjectEntityName] andFilter:searchFilter

How to get a diffable snapshot from an NSFetchResultsController in iOS 13?

雨燕双飞 提交于 2020-05-26 02:30:38
问题 So here we are in WWDC 2019 video 230, and starting at about minute 14 it is claimed that NSFetchedResultsController now vends an NSDiffableDataSourceSnapshot, so we can just apply it directly to a diffable data source (UITableViewDiffableDataSource). But this is not quite what they say, or what we get. What we get, in the delegate method controller(_:didChangeContentWith:) , is an NSDiffableDataSourceReference. How do we get from this to an actual snapshot, and what should my diffable data

How to get a diffable snapshot from an NSFetchResultsController in iOS 13?

心已入冬 提交于 2020-05-26 02:29:03
问题 So here we are in WWDC 2019 video 230, and starting at about minute 14 it is claimed that NSFetchedResultsController now vends an NSDiffableDataSourceSnapshot, so we can just apply it directly to a diffable data source (UITableViewDiffableDataSource). But this is not quite what they say, or what we get. What we get, in the delegate method controller(_:didChangeContentWith:) , is an NSDiffableDataSourceReference. How do we get from this to an actual snapshot, and what should my diffable data

How to get a diffable snapshot from an NSFetchResultsController in iOS 13?

为君一笑 提交于 2020-05-26 02:28:39
问题 So here we are in WWDC 2019 video 230, and starting at about minute 14 it is claimed that NSFetchedResultsController now vends an NSDiffableDataSourceSnapshot, so we can just apply it directly to a diffable data source (UITableViewDiffableDataSource). But this is not quite what they say, or what we get. What we get, in the delegate method controller(_:didChangeContentWith:) , is an NSDiffableDataSourceReference. How do we get from this to an actual snapshot, and what should my diffable data

iOS today extension with core data

佐手、 提交于 2020-05-23 10:07:05
问题 I am trying to make a today extension for my ios app. That today extension will display the 'next' Course based on data saved with core data. I've been doing some research and I understand I have to share my persistentContainer with an appGroup. So I did : enabled appGroups for both ios app and today extension targets. coded a function to share it : public extension NSPersistentContainer { func addToAppGroup(id: String) { guard let fileContainer = FileManager.default.containerURL

What kind of queries in Core Data can profit from R-Tree index on attributes?

穿精又带淫゛_ 提交于 2020-05-15 12:24:59
问题 After reading this article https://www.sqlite.org/rtree.html about the R*Tree in SQLite, i am currently experimenting with a 2-Dim R-Tree in a Core Data model. Particularly i expected (maybe somewhat naively) some kind of select statement on the index table but i did not see any in the SQLite debug trace when executing a fetch statement on the Region entity with indexed attributes (see predicateBoundaryIdx in the code below). My questions are: how must a Core Data model (entities, attributes)

What kind of queries in Core Data can profit from R-Tree index on attributes?

大憨熊 提交于 2020-05-15 12:22:45
问题 After reading this article https://www.sqlite.org/rtree.html about the R*Tree in SQLite, i am currently experimenting with a 2-Dim R-Tree in a Core Data model. Particularly i expected (maybe somewhat naively) some kind of select statement on the index table but i did not see any in the SQLite debug trace when executing a fetch statement on the Region entity with indexed attributes (see predicateBoundaryIdx in the code below). My questions are: how must a Core Data model (entities, attributes)