Made using SwiftUI, StayFitShop is a shopping application that enables users to browse and search products downloaded from the server and cached using Core Data Framework, add them to Cart, create their user profile and Checkout.
Here are some of the tools and techniques I used:
- MVVM design pattern
- Core Data Framework
- Swift Package Manager
Views in this app are shown in a tab bar and navigation views within each tab. Products are downloaded once when the app first starts and saved to persistant storage using Core Data Framework. Images are cached as well using SDWebImageSwiftUI to lessen the network usage and increase performance.
Each product can be added and removed from cart freely and the cart is being saved using Core Data. To manage data I used a Singleton in the CoreDataManager so I can access what I need from all over the app.
Users need to create their profile on checkout or use the dedicated tab "Profile" which is also saved using Core Data.
Here is the app in action:
I tried my best to optimize the whole app and I am aware of some issues regarding memory (some views don't get deallocated properly) which I did not know how to solve, but when in use, the app doesn't use more than 80 Mb of memory which I thought was fine. I do intend to come back to this app again and make improvements.
This app has no real backend so I made my own JSON and made up some dummy data just to have something to download from the server. The images for this app are all from Pixabay and Unsplash which are free resources and you can check out their licence information here: Pixabay license and here: Unsplash License. Users cannot actually purchase these products and the ordering works using Reqres service which upon successful POST request, returns the request back as is. I needed something to accept request and return data back so I can simulate an ordering process in the app since there is no real backend.
What I learned building this app
This is my first slightly larger app using SwiftUI, so there were some problems, but I made it work and learned some stuff:
- How to use Singletons to access data from other structs and classes easier.
- How to set up Core Data in SwiftUI and create NSManagedObjectSubclasses manually to deal with optionals coming from Core Data and access properties in views in a more clean way.
- How to save, edit and delete data in Core Data Framework
- How to use searchable in SwiftUI to make a list searchable in a very simple way.
- How to use MVVM pattern to create views that do not do logic (or very little of it)
- How to work with @ObservableObject & @StateObject.
- How to use extensions to do things like hide keyboards, play haptics etc.
- How to use @Environment for all kinds of different purposes like Managed Object Context dismissing modals etc.
- How to use Swift Package Manager to install dependencies and use them.
I learned so much about SwiftUI building this app and I really like this framework. I truly think this is the future of iOS Development. Sometimes, dealing with states is tricky, but the way I can build views very quickly using SwiftUI is inspiring.
Check out the project on my github repo: