An app to manage your expenses which you will waste (just like me), used MVVM architecture.
I have built a cache manager to store all the user transactions data in the memory as a cache. If you want to implement your custom class to manage them, you can do the following:
- Create a class which conforms to the protocol
UserTransaction
. - Implement the functions defined inside the protocol.
protocol UserTransaction {
func isUserAlreadyExist(userName: String) -> Bool
func removeUser(userName: String)
func saveTransaction(userName: String, transactions: [Transaction])
func getTransactions(userName: String) -> [Transaction]
func removeTransaction(userName: String, transactions: [Transaction])
func getUserExpenseModel(userName: String) -> UserExpenseModel?
}
class YourCustomClass: UserTransaction {
// UserTransaction Implementation
}
- Pass the same class as a parameter(dependency injection) where
TransactionListViewModel
is initialized, inside theExpense_TrackerApp.swift
.
@StateObject var transactionViewModel = TransactionListViewModel(userAPIDelegate: YourCustomClass())