Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

``` let viewModel = ViewModel(arg) _viewModel = StateObject(wrappedValue: viewModel) ``` Have you ever initialized a StateObject like this? 🤨 As it turns out, this code is actually incorrect and contains a very subtle bug 😱 Let me explain 😌

17,116 görüntüleme • 1 yıl önce •via X (Twitter)

10 Yorum

Cocoanetics  profil fotoğrafı
Cocoanetics 1 yıl önce

OMG I think I have this exact mistake in multiple places!!! Thank you for this!

Vincent Pradeilles profil fotoğrafı
Vincent Pradeilles1 yıl önce

It’s such a tricky one 🫠

Sau profil fotoğrafı
Sau1 yıl önce

Good catch!! I need to fix a couple of them 😂🔥🔥

1Dante profil fotoğrafı
1Dante1 yıl önce

Wow, I always do as in example, thanks for clarifying this potential issue.

Michael Schwab profil fotoğrafı
Michael Schwab1 yıl önce

Great content. It happens to be what I’m grappling with right now.

Jakob Joseph profil fotoğrafı
Jakob Joseph1 yıl önce

Init it in .task instead :)

Vincent Pradeilles profil fotoğrafı
Vincent Pradeilles1 yıl önce

That's also a possibility, but it does require making the values optional, right?

Nicolai Schneider profil fotoğrafı
Nicolai Schneider1 yıl önce

Thank you, I’m sure I’ve made this mistake here and there before!

José Gutiérrez profil fotoğrafı
José Gutiérrez1 yıl önce

Do you have the link for the article that you mention in the end?

Dong Nguyen profil fotoğrafı
Dong Nguyen1 yıl önce

I like simplicity, so I will create a static variable in a class that I call ‘Memory’ :D I don’t like viewModel with constructors that have additional parameters.

Benzer Videolar