We’ve arrived at day 72 of the 100 Days of SwiftUI! Yesterday, we’ve seen how to fetch data from Wikipedia and sort the results we got in a way that makes sense to our users. Today, we’re going to look at MVVM which stands for Model View View-Model. This is in essence a way we structure our code. We’ll also be enabling biometric authentication, so let’s dive in!
Introducing MVVM into your SwiftUI project
My bit on MVVM will be quite short. As mentioned above, this is a particular way of structuring our SwiftUI code and is called an architectural design pattern.
The pattern we’re going to look at is called MVVM, which is an acronym standing for Model View View-Model. This is a terrifically bad name, and thoroughly confuses people, but I’m afraid we’re rather stuck with it at this point. There is no single definition of what is MVVM, and you’ll find all sorts of people arguing about it online, but that’s okay – here we’re going to keep it simple, and use MVVM as a way of getting some of our program state and logic out of our view structs. We are, in effect, separating logic from layout.Hacking with Swift, Paul Hudson (@twostraws).
Locking our UI behind Face ID
To finish this project, we’re going to enable and require authentication through Face ID. This means that the app’s UI can’t be viewed until the user has been authenticated. Since the data in the Bucket List app is private, this seems appropriate.
We’ve already seen how to implement the biometric authentication features in SwiftUI a few days ago. Now we just need to finish it.
And that’s it for day 72 and yet another project has been finished and is under our belt. I’ve said it before, but the difficulty has really ramped up and I’m finding it more and more difficult to grasp what exactly is happening.
This is okay though! Learning isn’t always easy and struggling through it is good, it helps cement what you’ve learned. This is also the reason I’ll be coming back to many parts of the second half of this course after I’ve finished it: a fresh mind to absorb everything again will work wonders and will allow me to tackle the challenges I’ve skipped.
For now, it’s time to recharge and look forward. See you tomorrow!
100 Days of SwiftUI – Day 72