core-data

Update State-variable Whenever CoreData is Updated in SwiftUI

淺唱寂寞╮ 提交于 2021-02-08 11:18:19
问题 After updating some data from CoreData, I also want to update a State -variable to the number of returned results. When CoreData is changed, the Stepper should always be set to the number of returned results. However, onAppear fires also when I use the Stepper . How can I check in onAppear whether CoreData was changed or the Stepper was used? Is that even possible? import SwiftUI struct ContentView: View { @State var numberOfResults = 0 @FetchRequest(entity: YourModel.entity(),

Mac OSX Core Data App - keep Production data separate from debug data

六眼飞鱼酱① 提交于 2021-02-08 10:17:37
问题 I have created a Mac OSX Core Data business app. My issue is that whether I am running the app in Debug mode via Xcode or running my own personal production version (from the Mac App Store), both use the same data (i.e. the same sandbox area). I need to be able to mess with the Debug version data without affecting my production copy. Is there a Project Setting I can use to change the debug sandbox location, or at the very least change the data location? 回答1: I have separated my Live/Debug

How to build inverse relationship to Entity which has more than two relationship to it?

流过昼夜 提交于 2021-02-08 08:04:37
问题 I have an entities Group and Person with relationships: Group: Group.leader -> Person (To One) Group.looser -> Person (To One) Group.others ->> Person (To Many) In leader , looser and others set I could have different Person entities. Same Person could be leader in one group, looser in second and appears in others set in third group. in Person entity I have To-Many relationship groups which should connect Person: Person.groups ->> Group (should be enough but warnings) Because I can make only

How to build inverse relationship to Entity which has more than two relationship to it?

守給你的承諾、 提交于 2021-02-08 08:01:32
问题 I have an entities Group and Person with relationships: Group: Group.leader -> Person (To One) Group.looser -> Person (To One) Group.others ->> Person (To Many) In leader , looser and others set I could have different Person entities. Same Person could be leader in one group, looser in second and appears in others set in third group. in Person entity I have To-Many relationship groups which should connect Person: Person.groups ->> Group (should be enough but warnings) Because I can make only

SwiftUI Core Data Binding TextFields in DetailView

家住魔仙堡 提交于 2021-02-08 05:55:51
问题 I have a SwiftUI app with SwiftUI App lifecycle that includes a master-detail type list driven from CoreData. I have the standard list in ContentView and NavigationLinks to the DetailView. I pass a Core Data entity object to the Detailview. My struggle is setting-up bindings to TextFields in the DetailView for data entry and for editing. I tried to create an initializer which I could not make work. I have only been able to make it work with the following. Assigning the initial values inside

Fetching child sum from Core Data

ⅰ亾dé卋堺 提交于 2021-02-07 19:55:04
问题 Lets say I have three Entitys. Person: name address (to-many-salary) and (to-many-loans) Salary: income tax Rel: (to-one-Person) Bills amount Rel: (to-one-person) How do I perform a fetch that have a result like this: John Doe, SUM>income, SUM>amount Eva Doe, SUM>income, SUM>amount Using Swift 回答1: This is probably most easily done using Key Value Coding "collection operators" (see here) rather than a fetch. For each person : let name = person.name let totalIncome = person.valueForKeyPath(

Fetching child sum from Core Data

徘徊边缘 提交于 2021-02-07 19:54:16
问题 Lets say I have three Entitys. Person: name address (to-many-salary) and (to-many-loans) Salary: income tax Rel: (to-one-Person) Bills amount Rel: (to-one-person) How do I perform a fetch that have a result like this: John Doe, SUM>income, SUM>amount Eva Doe, SUM>income, SUM>amount Using Swift 回答1: This is probably most easily done using Key Value Coding "collection operators" (see here) rather than a fetch. For each person : let name = person.name let totalIncome = person.valueForKeyPath(

Why doesn’t NSFetchRequest.shouldRefreshRefetchedObjects work?

寵の児 提交于 2021-02-07 18:35:21
问题 I’m trying to update and save a managed object in one context and then access the updated attribute value in another context. The documentation for shouldRefreshRefetchedObjects says: By default when you fetch objects, they maintain their current property values, even if the values in the persistent store have changed. Invoking this method with the parameter YES means that when the fetch is executed, the property values of fetched objects are updated with the current values in the persistent

CloudKit and Core sync data between devices

僤鯓⒐⒋嵵緔 提交于 2021-02-07 11:55:40
问题 I created a simple Notes app based on Core data . Now i want add sync between user devices. And all articles that i read (this, this) said that i should fully get rid of my core data database, and all my code will lost and rework all with ICloud kit ? The is no way to sync data from Core Data to ICloud ? And if i get rid of core data, how my app will work offline ? And please suggest good simple projects with ICloud sync P.S. I googled about an hour. Icloud is deprecated so do sync with it is

The given data did not contain a top-level value error when attempting to decode json into NSManagedObject

牧云@^-^@ 提交于 2021-02-07 10:53:49
问题 While migrating an app from Realm to CoreData, I'm attempting to parse the following JSON structure: { "username": "972542052677", "displayName": "Arik", "countryCode": "972", "status": "Busy", "walletPublicKey": "XgWDiGMFRPDRVnRq8nxu7NyMLuT4Uez7mJ", "lastSeen": "2020-08-05T08:12:57.5267881", "isOnline": false } I need to create an NSManagedObject from this data so I'm following this tutorial: https://medium.com/@andrea.prearo/working-with-codable-and-core-data-83983e77198e This is the model.