SwiftUI MVVM Tutorial: Simple Example with ObservableObject

  Рет қаралды 20,774

Logan Koshenka

Logan Koshenka

Күн бұрын

Пікірлер: 92
@mustafaokay1302
@mustafaokay1302 3 жыл бұрын
This is the only basic mvvm tutorial for beginners and believe me I searched all the internet in different languages, thanks man this helped me a lot, keep doing it 👍
@logankoshenka
@logankoshenka 3 жыл бұрын
Great to hear :) Thank you!!!
@Ikemo4
@Ikemo4 2 жыл бұрын
Retweet
@logankoshenka
@logankoshenka 2 жыл бұрын
Love hearing that
@williams.7314
@williams.7314 Жыл бұрын
Thank you. I come from a .NET background with desktop publishing, so I was looking for an MVVM tutorial. So. Many. People. don't understand well enough to explain it well. That being said, as the rest of the comments suggest, well done sir, well done. Exactly what I needed.
@logankoshenka
@logankoshenka Жыл бұрын
thank you!!
@DmitriyChurilov
@DmitriyChurilov Жыл бұрын
Great introduction into the concept. Thank you!
@SantiLucero098
@SantiLucero098 Жыл бұрын
Very clear and simple, thank you man!
@logankoshenka
@logankoshenka Жыл бұрын
💪
@jamesmeegan2066
@jamesmeegan2066 Жыл бұрын
That was great, exactly what I needed and simple to understand.
@logankoshenka
@logankoshenka Жыл бұрын
love it - thanks for watching!
@TidalWaveDan
@TidalWaveDan Жыл бұрын
You sir, had by far the most understandable video in the subject. Thank you. I will be subscribing and recommending your channel to others trying to learn.
@logankoshenka
@logankoshenka Жыл бұрын
I appreciate that, glad you liked it!
@joaquimmenezes7396
@joaquimmenezes7396 10 ай бұрын
this tutorial was so cool, i understood concepts better ....
@logankoshenka
@logankoshenka 10 ай бұрын
great!!
@MrDaluti
@MrDaluti Жыл бұрын
Very well explained, thank you Sir, simple but effective. Please keep up the good work. 👏
@logankoshenka
@logankoshenka Жыл бұрын
means a lot - thank you!
@AntiSmithhh
@AntiSmithhh 2 жыл бұрын
ObservedObject occasionally works sometime. sometime doesn't and shouldn't. It should be StateObject in all similar cases. As for me, it's very clearly described in apple documentation.
@logankoshenka
@logankoshenka 2 жыл бұрын
really?
@AntiSmithhh
@AntiSmithhh 2 жыл бұрын
@@logankoshenka really! If I'm right, ObservedObject is like 'weak' reference and StateObject is like 'strong' one. But wrapper implementation keeps object alive in some cases when we are using ObservedObject. So using ObservedObect instead StateObject doesn't lead crushes and problem just stay hidden in simple cases. P.S.: thank you for MVVM example.
@logankoshenka
@logankoshenka 2 жыл бұрын
Ahhh that makes sense - thank you for this!
@ob6217
@ob6217 2 жыл бұрын
ur light-mode just mademy day brighter and eyes darker😜 btw, thanks a lot sensei 🤝
@logankoshenka
@logankoshenka 2 жыл бұрын
hahaha thanks for watching
@glennmiller394
@glennmiller394 2 жыл бұрын
I get it now. Well done.
@logankoshenka
@logankoshenka 2 жыл бұрын
thanks for watching!
@SOK-gn6hw
@SOK-gn6hw 2 жыл бұрын
How can I change the array with a button. like if Jon Snow change his email and wanna change this in app how can I do that ?
@goisborges
@goisborges Жыл бұрын
Amazing tutorial
@logankoshenka
@logankoshenka Жыл бұрын
thank you!
@ob6217
@ob6217 2 жыл бұрын
i wanna ask something, where are those function come from? the people.reverse and the others.. i dont see it.. mind to explain, please??
@ob6217
@ob6217 2 жыл бұрын
ah i get it rn, thank youu
@dmitrygolovin8066
@dmitrygolovin8066 3 жыл бұрын
Nice man! Thanks for all the great content
@logankoshenka
@logankoshenka 3 жыл бұрын
my guy I appreciate it 🤘🏼
@alexdiaz1712
@alexdiaz1712 2 жыл бұрын
This is exactly what I was looking for! Thank you for making this awesome video and making me laugh 😂
@logankoshenka
@logankoshenka 2 жыл бұрын
haha glad you like it - welcome!
@georgeikwegbu5284
@georgeikwegbu5284 2 жыл бұрын
For real, I laughed all through, now I have to rewatch it again 😩🤣🤣🤣🤣, nice tutorial Logan, thanks
@kevindesouza6143
@kevindesouza6143 Жыл бұрын
At 5:30 timestamp, you add the ObservableObject Protocol. Using Swift 5 and Xcode 14.1 I get an error there. Basically it wants to add a Generic Type to the Observable object.When I add it says this is not confirm to ObservableOBject Protocol. Can't proceed further till this is resolved. So pls help. Also I get an error when I use the Identifiable Protocol.
@logankoshenka
@logankoshenka Жыл бұрын
hmm, I wonder if this could be related to Swift versions? If I find an answer I'll reply in this thread.
@johnpill1
@johnpill1 Жыл бұрын
How would you use this approach to access the same data across multiple views, do you require the environment object at that point?
@logankoshenka
@logankoshenka Жыл бұрын
yeah I think environment object is your best bet for that … check out the tutorials that tundsdev has on this, really helpful stuff 💪
@johnpill1
@johnpill1 Жыл бұрын
@@logankoshenka I've actually been using the tutorial you mention, but wondered if there was a simpler way!
@mattmarshall1834
@mattmarshall1834 2 жыл бұрын
Great tutorial. To the point.
@logankoshenka
@logankoshenka 2 жыл бұрын
thanks!
@anhhanry7167
@anhhanry7167 2 жыл бұрын
HI, just learn of this mvvm model based on @observable object, this is new to me, thanks for the tutorial... but I need to goto detail view if I tap/click on each view model, could you help ? (pointing to which info to pass ) because I don't know how to pass data ( each of model ) to the detail view model ( how to declare variable) , thanks
@logankoshenka
@logankoshenka 2 жыл бұрын
Glad it was helpful! I'm not sure I understand what you mean - could you elaborate?
@anhhanry7167
@anhhanry7167 2 жыл бұрын
@@logankoshenka for example > each person ( in the List) if click, I need to display a next screen ( a detail view ) to display more information ( such as a photo, title, salary, department etc..of the person ) theerefore I need to pass the object into this new view meaning the new detail view would require the correct person ( information of object) to display. I would design the new view but I need the info of the person from previous screen which tie to @Observableobject.
@DaveJacobseniOS
@DaveJacobseniOS 3 жыл бұрын
I couldn’t follow any of this because my eyes were damaged from light mode. Jk, this is solid stuff and a great refresher for me👌
@logankoshenka
@logankoshenka 3 жыл бұрын
hahaha hey you're talking to a fellow member of team dark mode so I get it 😅 thank ya
@ForhadDreams
@ForhadDreams 2 жыл бұрын
Great example!. can you please a short MVVC video tutorial for fetching API data CRUD[create, get, update, delete]? Please.....
@logankoshenka
@logankoshenka 2 жыл бұрын
Thanks for the suggestion! You may have a typo - it's typically MVVM or MVC.
@ForhadDreams
@ForhadDreams 2 жыл бұрын
@@logankoshenka oh! sorry. it's MVVM. Please. :)
@logankoshenka
@logankoshenka 2 жыл бұрын
@@ForhadDreams gotcha!
@ForhadDreams
@ForhadDreams 2 жыл бұрын
@@logankoshenka thanks. Hope we will get it soon!
@arturoescutialopez1900
@arturoescutialopez1900 Жыл бұрын
Nice video. I´m just wondering, is there a reason for ViewModel to be a class and not a struct? you could use @State in the view make viewmodel a struct and handle inheritance with protocols if needed. Why would you need a reference to the viewmodel and not a copy of its values?
@logankoshenka
@logankoshenka Жыл бұрын
In the case that we're using the viewModel in more than one place, I would want all references to be updated. That's the main reason for using a class in this scenario.
@deiv319x
@deiv319x 8 ай бұрын
I love the subtle satire 😂😂
@logankoshenka
@logankoshenka 8 ай бұрын
😄 thank ya
@chingshenchen
@chingshenchen 2 жыл бұрын
Thank you for sharing. I have subscribed your channel. Keep doing it. :)
@logankoshenka
@logankoshenka 2 жыл бұрын
Thank you so much! More videos coming soon :)
@tarun_reddy
@tarun_reddy 3 жыл бұрын
Thanks for this king
@logankoshenka
@logankoshenka 3 жыл бұрын
🤝
@tharindudarshana6480
@tharindudarshana6480 2 жыл бұрын
Great tutorial. Thank you
@logankoshenka
@logankoshenka 2 жыл бұрын
Thank you!
@TheShambi
@TheShambi Жыл бұрын
Hi, wouldn't it make more sense to have the people array inside a model and not the viewModel. let's say you have different sets of potential People array. The viewModel will load them in the constructor based on the array you want. What I mean is that the viewModel should have the possibility to load a lot of different models and not include hard coded values?
@logankoshenka
@logankoshenka Жыл бұрын
yeah I see what you're saying ... with different sets of people, it'd definitely make sense for that data to be available inside of a model.
@franziskaschneider8606
@franziskaschneider8606 2 жыл бұрын
Finally a simple example and not unnecessarily complicated. Thanks! I experimented a bit with the code. The array is updated in the view, but if I change the name of a person, the view is not updated. What do I have to do to make this data binding work?
@logankoshenka
@logankoshenka 2 жыл бұрын
Thank you! And just to be clear, are you changing the name of a person in code or while running the app?
@franziskaschneider8606
@franziskaschneider8606 2 жыл бұрын
during runtime -> In the PersonViewModel class I added a renameFirstPerson() func.
@logankoshenka
@logankoshenka 2 жыл бұрын
@@franziskaschneider8606 do you mind sharing that function here? I’ll gladly take a look!
@edgarhernandez65
@edgarhernandez65 3 жыл бұрын
thanks, great video. I would love for you to make an example by consuming an api Saludos desde México
@logankoshenka
@logankoshenka 3 жыл бұрын
Muchas gracias!
@tokero5199
@tokero5199 Жыл бұрын
Thank you for the explanation, I'm not a fan of you importing SwiftUI in the model and the viewModel, you really should keep those UI agnostic.
@logankoshenka
@logankoshenka Жыл бұрын
ah good point, thanks for the feedback 🤝
@myga77
@myga77 3 жыл бұрын
Show us how to create custom swipes with your scrollview list, not with the regular list in SwiftUI I can't figure out how to find the index of each cell in a scrollView
@logankoshenka
@logankoshenka 3 жыл бұрын
custom swipe actions like horizontally?
@thedrenkemp124
@thedrenkemp124 2 жыл бұрын
Would you ever make a video on custom keyboard? How to create custom keyboard?
@logankoshenka
@logankoshenka 2 жыл бұрын
I’ll look into it!
3 жыл бұрын
Thanks Logan ;)
@logankoshenka
@logankoshenka 3 жыл бұрын
Of course!
@thirashapw
@thirashapw 3 жыл бұрын
Love it. Keep doing ❤️
@logankoshenka
@logankoshenka 3 жыл бұрын
thank you!
@Danyil-ip3ll
@Danyil-ip3ll 2 жыл бұрын
Thank you.Make more videos!!!!Hello from Ukraine 🇺🇦
@logankoshenka
@logankoshenka 2 жыл бұрын
more coming soon!
@WilfClegg
@WilfClegg 2 жыл бұрын
Thank you for this video, Logan! This makes it very simple to understand the MVVM SwiftUI structure. Other videos seem to confuse the basics because of other processing features (which only serve to conflate the basic MVVM method). I tried adding an array sort, to sort the array by name. I can't seem to get it to work. I don't understand how this simple addition can be so complicated. Is there any advice you might be able to share? Thanks!
@logankoshenka
@logankoshenka 2 жыл бұрын
Thank you, glad you liked it! Where are you calling the sort method?
@izzzanaaami
@izzzanaaami 2 жыл бұрын
I live in Russia, and I've watched so many video tutorials and courses about it, but most of them are useless because their authors themselves didn't fully understand what they were doing, or they have very little experience, in general, thanks from Russia
@logankoshenka
@logankoshenka 2 жыл бұрын
thanks for watching!
@followerOfJesus723
@followerOfJesus723 Жыл бұрын
I'm sorry to be the spoil-sport/negative Nancy but, there are tons of videos that show this. Use an actual Networking Service that actually makes an API call. Then show how to create a dependency manager so you don't make the service in the ViewModel. When you declare the viewModel in the View, it should be optional and not initialized. Then use a dependency provider to initialize it, (possibly in the scene or app delegate or whatever) but the responsibility for initializing the service should not be delegated to the view. That isn't MVVM.
@logankoshenka
@logankoshenka Жыл бұрын
I appreciate the feedback! I’m always doing my best with what I know, and this video specifically was meant to be as simple as possible. You should make a video demonstrating this! I’d love to see it in action 🤝
@pren5948
@pren5948 Жыл бұрын
Thanks
@logankoshenka
@logankoshenka Жыл бұрын
🤝
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 2,8 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 327 МЛН
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 79 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 24 МЛН
SwiftUI API / JSON Tutorial with Async Await Example
9:52
Logan Koshenka
Рет қаралды 26 М.
Data Flow in a SwiftUI App
33:15
CodeWithChris
Рет қаралды 54 М.
MVVM Tutorial for Absolute Beginners with SwiftUI (iOS 2022)
10:36
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 2,8 МЛН