I can't find the problem.. - The simulator is stopping after opening the app...
Database`property wrapper backing initializer of ContentViewViewModel.currentUserId:
0x104c12bd0 <+0>: sub sp, sp, #0x50
0x104c12bd4 <+4>: stp x29, x30, [sp, #0x40]
0x104c12bd8 <+8>: add x29, sp, #0x40
0x104c12bdc <+12>: str x8, [sp, #0x10]
0x104c12be0 <+16>: mov x8, x0
0x104c12be4 <+20>: str x8, [sp, #0x8]
0x104c12be8 <+24>: mov x0, x1
0x104c12bec <+28>: str x0, [sp, #0x18]
0x104c12bf0 <+32>: stur xzr, [x29, #-0x10]
0x104c12bf4 <+36>: stur xzr, [x29, #-0x8]
-> 0x104c12bf8 <+40>: stur x8, [x29, #-0x10]
0x104c12bfc <+44>: mov x1, x0
0x104c12c00 <+48>: stur x1, [x29, #-0x8]
0x104c12c04 <+52>: bl 0x1053b9a88 ; symbol stub for: swift_bridgeObjectRetain
0x104c12c08 <+56>: ldr x9, [sp, #0x8]
0x104c12c0c <+60>: ldr x8, [sp, #0x10]
0x104c12c10 <+64>: ldr x1, [sp, #0x18]
0x104c12c14 <+68>: add x0, sp, #0x20
0x104c12c18 <+72>: str x9, [sp, #0x20]
0x104c12c1c <+76>: str x1, [sp, #0x28]
0x104c12c20 <+80>: adrp x1, 2556
0x104c12c24 <+84>: ldr x1, [x1, #0xa00]
0x104c12c28 <+88>: bl 0x104c12c40 ; Combine.Published.init(wrappedValue: Value) -> Combine.Published<Value> at <compiler-generated>
0x104c12c2c <+92>: ldr x0, [sp, #0x18]
0x104c12c30 <+96>: bl 0x1053b91a0 ; symbol stub for: swift_bridgeObjectRelease
0x104c12c34 <+100>: ldp x29, x30, [sp, #0x40]
0x104c12c38 <+104>: add sp, sp, #0x50
0x104c12c3c <+108>: ret
//
// ContentViewViewModel.swift
// Database
//
// Created by Maxi on 25.03.24.
//
import Firebase
import FirebaseAuth
import Foundation
class ContentViewViewModel: ObservableObject {
@Published var currentUserId: String = ""
private var handler: AuthStateDidChangeListenerHandle?
init () {
self.handler = Auth.auth().addStateDidChangeListener{ [weak self] _, user in
DispatchQueue.main.async {
self?.currentUserId = user?.uid ?? ""
}
}
}
public var isSignedIn: Bool {
return Auth.auth().currentUser != nil
}
}
//
// ContentView.swift
// Database
//
// Created by Maxi on 25.03.24.
//
import Firebase
import FirebaseAuth
import SwiftUI
struct ContentView: View {
@StateObject var viewModel = ContentViewViewModel()
var body: some View {
VStack {
NavigationView {
if viewModel.isSignedIn, !viewModel.currentUserId.isEmpty {
//signed in
HomeView()
} else {
LoginView()
}
}
.padding()
}
}
}
struct ContentView_Previews: PreviewProvider{
static var previews: some View {
ContentView()
}
}
//
// HomeView.swift
// Database
//
// Created by Maxi on 25.03.24.
//
import SwiftUI
struct HomeView: View {
var body: some View {
Text("Welcome to your Account!")
}
}
#Preview {
HomeView()
}
//
// LoginViewViewModel.swift
// Database
//
// Created by Maxi on 25.03.24.
//
import FirebaseAuth
import Foundation
class LoginViewViewModel: ObservableObject {
@Published var email = ""
@Published var password = ""
@Published var errorMessage = ""
init() {}
func login() {
guard validate() else {
return
}
//Try log in
Auth.auth().signIn(withEmail: email, password: password)
}
private func validate() -> Bool {
errorMessage = ""
guard !email.trimmingCharacters(in: .whitespaces).isEmpty,
!password.trimmingCharacters(in: .whitespaces).isEmpty else {
errorMessage = "Bitte füllen Sie alle Felder aus."
return false
}
guard email.contains("@") && email.contains(".") else {
errorMessage = "Bitte geben Sie eine gültige Email-Adresse ein."
return false
}
return true
}
}
//
// LoginView.swift
// Database
//
// Created by Maxi on 25.03.24.
//
import SwiftUI
struct LoginView: View {
@StateObject var viewModel = LoginViewViewModel()
var body: some View {
NavigationView {
VStack {
//Header
HeaderView()
if !viewModel.errorMessage.isEmpty{
Text(viewModel.errorMessage)
.foregroundColor(Color.red)
}
Form{
TextField("E-Mail Adresse", text: $viewModel.email)
.textFieldStyle(DefaultTextFieldStyle())
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
SecureField("Passwort", text: $viewModel.password)
.textFieldStyle(DefaultTextFieldStyle())
CreateAccountButton(
title: "Anmelden",
background: .blue) {
viewModel.login()
}
}
//Create ACC
VStack {
Text ("Neu hier?")
//Show registartion
NavigationLink ("Erstelle einen Account",
destination: RegisterView())
}
}
}
}
}
struct LoginView_Previews: PreviewProvider{
static var previews: some View {
LoginView()
}
}