Christian Selig on Nostr: SwiftUI noob question: I understand why my ViewModel is being initialized twice, but ...
SwiftUI noob question: I understand why my ViewModel is being initialized twice, but why is it not being *deinitialized*?
It's created, then a second later when appState.show is changed, the view is recomputed, and view, and its ViewModel, are created anew. Cool! But why is the old one not deinitialized? What's holding onto it?
Sample code:
https://gist.github.com/christianselig/d88b1a4d1989b973689ae62d4691162f Published at
2024-05-19 20:40:11Event JSON
{
"id": "bd10e36fd18ffc2624fd9642f9c92893fc974696e3ab90f5dac9cef838c38bcb",
"pubkey": "de6adda4d139627ce8f9cf05ef27c7cd1de9895363e5f303667f761bec318716",
"created_at": 1716151211,
"kind": 1,
"tags": [
[
"proxy",
"https://mastodon.social/users/christianselig/statuses/112469685808397232",
"activitypub"
]
],
"content": "SwiftUI noob question: I understand why my ViewModel is being initialized twice, but why is it not being *deinitialized*? \n\nIt's created, then a second later when appState.show is changed, the view is recomputed, and view, and its ViewModel, are created anew. Cool! But why is the old one not deinitialized? What's holding onto it?\n\nSample code: https://gist.github.com/christianselig/d88b1a4d1989b973689ae62d4691162f\n\nhttps://files.mastodon.social/media_attachments/files/112/469/685/532/237/276/original/49d716971ab537d4.png",
"sig": "b00fc474815007c32acc298fff65cf2e2224eabbaef6e930012489c502bdb83037d899d9af70a11ae693efa504211d7242244cbcecd9af6af927a8c9a4be2b23"
}