In this SwiftUI fundamentals tutorial, I will talk about the difference between class and structs. This is important because they look very similar but have fundamentally different properties and use cases.
As an example I will define a data model for a SwiftUI view. The data flow in SwiftUI is very specific and it is important to understand how the updating mechanism works.
You want to always display the right data with the correct UI updates. Data models should be defined as structs. If you choose class as models, the SwiftUI views will in most cases not refresh. I will show you multiple example views with both structs and classes.
Because I always think of more stuff to talk about 😉, I also show you a useful approach to make SwiftUI views more reusable. You will get a quick introduction about protocols and generics for SwiftUI. This is a more advanced topic. So don’t worry if you struggle. It also took me quite some effort to understand this and make it work for my day-to-day SwiftUI programming.
If you liked what you learned and you want to see more, check out one of my courses!
👨💻 my SwiftUI course [ Ссылка ]
👨💻 my Core Data and SwiftUI course [ Ссылка ]
👩🏻💻 Combine course
[ Ссылка ]
⬇️ Playground files: [ Ссылка ]
More tutorials that would talk about SwiftUI data flow and more:
MVVM SwiftUI Tutorial [ Ссылка ]
Realm database in SwiftUI with MVVM [ Ссылка ]
How to best use Core Data with SwiftUI [ Ссылка ]
#SwiftUI #Class #Struct #Model
Ещё видео!