Post

Replies

Boosts

Views

Activity

Reply to How can I fix this leaking memory?
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.
Sep ’21
Reply to Async in Playground
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
Jun ’21
Reply to EnvironmentObject access
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.
Jun ’21