observedobject

What is the difference between @EnvironmentObject and @ObservedObject?

扶醉桌前 提交于 2021-02-08 15:12:37
问题 I have been reading about the property wrappers in SwiftUI and I see that they do a great job, but one thing which I really don't get is the difference between @EnvironmentObject and @ObservedObject . From what I learned so far, I see that @EnvironmentObject is used when we have an object that is needed in various places in our app but we don't need to pass it through all of them. For example if we have hierarchy A -> B -> C -> D and the object is created at A, it is saved in the environment

What is the difference between @EnvironmentObject and @ObservedObject?

丶灬走出姿态 提交于 2021-02-08 15:06:00
问题 I have been reading about the property wrappers in SwiftUI and I see that they do a great job, but one thing which I really don't get is the difference between @EnvironmentObject and @ObservedObject . From what I learned so far, I see that @EnvironmentObject is used when we have an object that is needed in various places in our app but we don't need to pass it through all of them. For example if we have hierarchy A -> B -> C -> D and the object is created at A, it is saved in the environment

Deleting CoreData Item which is also an @ObservedObject in DetailView causing App Crash in Swift 5

落爺英雄遲暮 提交于 2020-12-15 05:27:54
问题 i am currently working with SwiftUI and CoreData . Situation: I have a User Detail View with a Delete Button at the Bottom. When pressed, the Core Data Entry of the User is getting deleted and the App Navigation goes back to the Root Navigation View, which is a List of all Users. Problem: Every Time the Delete Button is clicked the App crashes with the following Error Message : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[User timeCreated]:

Deleting CoreData Item which is also an @ObservedObject in DetailView causing App Crash in Swift 5

本小妞迷上赌 提交于 2020-12-15 05:26:16
问题 i am currently working with SwiftUI and CoreData . Situation: I have a User Detail View with a Delete Button at the Bottom. When pressed, the Core Data Entry of the User is getting deleted and the App Navigation goes back to the Root Navigation View, which is a List of all Users. Problem: Every Time the Delete Button is clicked the App crashes with the following Error Message : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[User timeCreated]:

Assigning an ObservedState’s published value to a state

孤街浪徒 提交于 2020-06-28 06:41:26
问题 I have a state called time @State var time = 0 and an ObservedObject called timerWrapper @ObservedObject var timerWrapper = TimerWrapper() time can be updated from a child view and I want to be also able to update it using the timerWrapper (theObservedObject), if I use this: self.time = self.timerWrapper.remainingSeconds and do this: Text($time) The text doesn’t update. It only works if I do this: Text(self.timerWrapper.remainingSeconds) I know that’s because when remainingSeconds is

What is the difference between @State and @ObservedObject, can they both be used to persist state?

别来无恙 提交于 2020-04-17 04:33:08
问题 When I Googled "State vs ObservedObject" the first result was from Hacking with Swift and it said about @ObservedObject : This is very similar to @State except now we’re using an external reference type rather than a simple local property like a string or an integer. Can I use @ObservedObject to create persisted state? Is it as simple as @State is for simple properties and @ObservedObject is for complex objects , or is there more nuance to it? 回答1: @ObservedObject does not persist state Can I

What is the difference between @State and @ObservedObject, can they both be used to persist state?

痴心易碎 提交于 2020-04-17 04:30:09
问题 When I Googled "State vs ObservedObject" the first result was from Hacking with Swift and it said about @ObservedObject : This is very similar to @State except now we’re using an external reference type rather than a simple local property like a string or an integer. Can I use @ObservedObject to create persisted state? Is it as simple as @State is for simple properties and @ObservedObject is for complex objects , or is there more nuance to it? 回答1: @ObservedObject does not persist state Can I

SwiftUI custom View's ViewBuilder doesn't re-render/update on subclassed ObservedObject update

社会主义新天地 提交于 2020-03-25 19:22:50
问题 This one I've been researching for a few days, scouring the Swift & SwiftUI docs, SO, forums, etc. and can't seem to find an answer. Here is the problem; I have a SwiftUI custom View that does some state determination on a custom API request class to a remote resource. The View handles showing loading states and failure states, along with its body contents being passed through via ViewBuilder so that if the state from the API is successful and the resource data is loaded, it will show the