core-data

Adding elements on many-to-many relation

给你一囗甜甜゛ 提交于 2021-02-04 21:34:40
问题 I am making a project where (from the perspective of school) you can calculate each student average. You can register a student (first entity) on a screen and subjects (second entity) on another screen. Student has name, email, grade and average as atributes, and Subjects has name. They relate many-to-many with each other. I am trying to create a copy of subjects list to each student, then on each student i can register a grade to each subject. Like this: Model concept Model: !https://imgur

Migrate Core Data database from one app to another

橙三吉。 提交于 2021-02-04 21:29:44
问题 I have a Core Data database that I wish to pre-populate without having to load all the data on first launch. I'm trying to do this by creating a second app that takes care of the loading and copy the SQL database from that app to the new one. Initially I tried to simply copy the .sqlite file from the second app and copy the files into the first app like this: lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "GeoPointDB") let seededData:

Migrate Core Data database from one app to another

狂风中的少年 提交于 2021-02-04 21:28:08
问题 I have a Core Data database that I wish to pre-populate without having to load all the data on first launch. I'm trying to do this by creating a second app that takes care of the loading and copy the SQL database from that app to the new one. Initially I tried to simply copy the .sqlite file from the second app and copy the files into the first app like this: lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "GeoPointDB") let seededData:

EnvironmentObject does not work when sheet is presented

老子叫甜甜 提交于 2021-01-29 18:52:50
问题 I have a view that has managedObjectContext(Environment Variable). It works fine when presented in NavigationView with NavigationLink. But it does not work when the view is presented as a sheet. It gives me an error when I save some entity data. "The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)" Is there anything I am missing when using the Environment object. My code let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

Core Data + CloudKit not refreshing on other device automatically?

陌路散爱 提交于 2021-01-29 13:38:56
问题 I have my SwiftUI app working with Core Data + CloudKit. I am able to save new entries to the database from my Mac or iPhone. The app uses the exact same project/codebase for all devices. The only problem is that I need to close out of the app and re-open it to see any new entries made from the other device. I can immediately see the new entries made from the same device, but they do not appear on the other devices until I close and re-open the app on it. Am I missing something here? Do I

Filter by date only from datetime/datepicker in swift

主宰稳场 提交于 2021-01-29 08:24:37
问题 I am using datetime picker in form and inserting data as follows to core data entity (attribute) `appointment.date = appointmentDate.date //it is getting date as well and time appointment.title = "Appointment" do { try managedObjectContext.save()` and in another viewcontroller i am doing this to filter records based on date. I have a calendar which returns date. let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Appointment") let sortDescriptor = NSSortDescriptor(key: "date"

NSPersistentContainer will load in app, won't load in test target

眉间皱痕 提交于 2021-01-29 07:34:38
问题 This problem first appeared in my app project, but it's baffled me enough that I tried to simplify things by switching to a Swift Package where I get the same issue. In my project, I have a data model file called "Model.xcdatamodeld" (though the same problem appears no matter what the name). When I call the following init method in my running app, everything runs fine: init(title: String, then completion: @escaping ()->()) { self.container = NSPersistentContainer(name: title) container

Multiple 'Persistent Store Coordinators' opening the same 'Store' don't see each others changes

大城市里の小女人 提交于 2021-01-29 06:51:59
问题 TL;DR: I have two 'Persistent Store Coordinators' who open the same 'Store file'. When one Coordinator writes changes, the other is unaware of it. In my document-based app, I need to have multiple databases: 1. Document database (one per document) 2. Shared database (visible by all documents) Here's how I set up my stack: Having that setup is great because: Documents can't access each others stores Every document has access to the shared database file. But here's a problem. Suppose I have two

PromsieKit + Alamofire for loading paged HTTP Data

ぃ、小莉子 提交于 2021-01-28 19:06:51
问题 I am migrating some code from RestKit to Alamofire. I use MagicalRecord + AlamofireObjectMapper to map the JSON into CoreData objects. I am now faced with the following situation: My Data lives at this URL: http://domain.com/api/resources?start=XX&limit=YY Now I have to do this: Download the first page of data from a given URL using a page-size of 50 If the number of loaded objects is equal to the page-size increment the start parameter by the page size If the number is less than the page

Maintaining Complex Unidirectional Relationships in Core Data

╄→尐↘猪︶ㄣ 提交于 2021-01-28 14:20:32
问题 I am migrating a data model I have in Realm to Core Data (so I can sync with Ensembles). The model is a graph, and in Realm I am managing the integrity of the graph myself with rules about deletions etc in transactions. I have made an example graph here that aims to describe the crux of my problem. All objects in my graph are Things. Things have an ordered to-many relationship with their subThings. However, subThings have multiple ways they link back. For example, one DerivedFromThing type