I'm not sure, if it is intended by Apple or even allowed to use @EnvironmentObject inside the model code.
I think you should declare billModel in PDFManger as a simple let or var and set it yourself using an initializer:
Post
Replies
Boosts
Views
Activity
I think you declared your Property wrapper outside of a view struct (like on the to level of the Playground code) which is not supported.
I would suspect it has to do with the same limitation all of SwiftUI suffers: You can only declare 10 subviews inside of a view.
The usual workaround is to use Group{} like this:
HStack{
Group{
Item1
Item2
...
Item10
}
Group{
Item11
...
Item 20
}
}
Did you try
.sheet(isPresented: $showTest) {
FailingView().environmentObject(stateObj)
}
I can't see anything really broken about your code. Only .environmentObject(vm) in the body of ContentView is not necessary.
Did you try:
init() {
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] timer in
self?.getRandonNumber()
}
}
Capturing self is alway „dangerous“ and can lead to memory leaks. The timer/closure keeps a reference to the ViewModel and the ViewModel keeps a reference to the timer, therefore their memory is never released.
I don't know if your ViewModel is recreated many times during the run of your app, but if it where, this reference cycle would lead to a memory leak.
Interesting!
Unfortunately this is does not give the same result, depending on the views content. Try Circle().stroke() for example, to see the difference in rendering.
PS: is it supported on iPad Air 2 to begin with?
Playgrounds 4 will run on all devices capable of running iOS 15 and will be available later this year, was the information given at WWDC.
Sorry, I forgot about three additional things you have to do to use Swift concurrency in Playgrounds:
import _Concurrency
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
Like with every async function called from a synchronous context (the global context of your playground) you have to wrap your call to doStuff() in an async block and await it:
async{
await doStuff()
}
This is expected to change to
Task.async{
await doStuff()
}
in a later beta.
The following list of WWDC videos covering Swift concurrency should provide further background: Meet Swift Concurrency
I think your question can't be answered without you telling us how you create and pass your GlobalObj in the levels above?
Do you use @StateObject for example?
Additionally in the WWDC lounges someone asked:
I’ve had several intermittent crashes from environment objects being nil when I pass them to a sheet or NavigationLink. [...]
The answer was:
NavigationLink by design doesn’t flow EnvironmentObjects through to its destination as it’s unclear where the environmentObject should be inherited from. I suspect this might what’s causing your issue. In order to get the behavior you expect, you’ll have to explicitly pass the environmentObject through at that point.
Same here, but on a Mac with Intel CPU