Cat Cafe Manager is a training game project for learning SwiftUi. The following is implemented in this project:
- MVVM
- Asynchronous navigation
- Asynchronous work of URLSession with Rest-API
- Pagination works with/without API-KEY
- Actors
- MapKit
- SQLight with GRDB https://github.com/groue/GRDB.swift
- DI with Swinjcet https://github.com/Swinject/Swinject
CafeDetails View and Asynchronous Alert
Generic way: you can use asynchronous navigation in the view model as follows
@MainActor func adoptCat() async {
var selectedCat: CatModel = await navigation.pushViewGenericAsync(
view: CatAdoptView(),
animated: true,
enableSwipeBack: true,
title: "",
titleHidden: true,
defaultValue: CatModel.aNewCat
)
}
Collback way: you can use asynchronous navigation in the view model as follows
@MainActor func adoptCat() async {
var selectedCat = CatModel.aNewCat
await navigation.pushViewAsync(
view: CatAdoptView(
onCatSelect: { cat in
selectedCat = cat
self.navigation.popViewAsync()
}
),
animated: true
)
}
To use this application please enter you API KEY in AppConstants file in the field marked: "AccessKey"
The API will return a list of cats in random order unless you enter an API KEY.
Just register and get a free API-KEY https://thecatapi.com/
- The code involved in the above example is in this repository code. It is recommended to download and run the view.
- If you have better usage and suggestions about SwiftUI, look forward to sharing it!
- If there are omissions and errors in the examples in this article, please create a Issue !
- The example API is the cat API. https://thecatapi.com/
- Xcode 14.0
- iOS 15.2
SwiftUI is released under the MIT license. See LICENSE for details.
https://github.com/groue/GRDB.swift
https://github.com/Swinject/Swinject
https://matteomanferdini.com/swiftui