3 ms·
Swift is OK, but with the introduction of SwiftUI, we see some hypocrisy. We were all told to "prefer structs" over classes in Swift, but structs are always pa
by VerifiedReports 8mo ago
Swift is OK, but with the introduction of SwiftUI, we see some hypocrisy.
We were all told to "prefer structs" over classes in Swift, but structs are always passed by value.
We're also told to maintain "one source of truth" (which I'm sure a lot of us did anyway). But you can't do that when you're copying stuff all over the place.
So now what? I got so sick of trying to figure out how to pass structs into views for modification by the user that I made everything a class. What a relief. Now I could get back to work on functionality instead of constructing absurd gymnastics to get altered data back from a view.
I find the whole "structs are passed by value, classes by reference" thing hokey as hell and poor style. People reading the code don't know if the called function can change the passed-in object or not; they have to go see if it's a class or a struct. Lame.