쉽게 표현하면 viewmodel을 통해 Model과 View가 일을 처리하는 형태이다
struct User: Codable {
var uid: String
var email: String
var nickname: String
}
extension LoginView{
final class ViewMoel: ObservableObject{
var user : User
init() {
self.user = User(uid: "", email: "", nickname: "")
}
}
}
import SwiftUI
struct LoginView: View {
@StateObject var viewModel = ViewMoel()
var body: some View {
VStack{
Text(viewModel.user.uid)
Text(viewModel.user.email)
Text(viewModel.user.nickname)
}
}
}