I am making app which one of functionality is register user with firebase, but sometime when I register user I got app crash but user is added into db.
I am getting error like this: EXC_BAD_ACCESS (code=2, address=0x2600000000) or adres = 0x10 which mean the is some memory leak but when I use instrumental leak every thing is ok.
Second weird thing is that when I use instrumental leak I am not getting error (I added something like 40 users) but when I close instrumental and rebuilt I got crash in max 3 attempts.
// FormComponent.swift
// SpaceManager
//
// Created by Kuba Kromomołowski on 17/04/2024.
//
import Foundation
import SwiftUI
struct FormComponent: View {
var isRegister: Bool = true
@State private var repeatedPassword: String = ""
@StateObject private var loginHandler = LoginViewModel()
@StateObject private var registerHandler = RegisterViewModel()
@EnvironmentObject var permissionViewModel: PermissionViewModel
var body: some View {
Form {
TextField("Email", text: isRegister ? $registerHandler.email : $loginHandler.email)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(size: 25))
.multilineTextAlignment(.center)
.autocapitalization(.none)
.disableAutocorrection(true)
SecureField("Hasło", text: isRegister ? $registerHandler.password : $loginHandler.password)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(size: 25))
.multilineTextAlignment(.center)
.autocapitalization(.none)
.disableAutocorrection(true)
if (isRegister) {
SecureField("Powtórz haslo", text: $registerHandler.repeatedPassword)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(size: 25))
.multilineTextAlignment(.center)
.autocapitalization(.none)
.disableAutocorrection(true)
}
BtnClearComponet(btnText: isRegister ? "Zarejestruj się" : "Zaloguj się",
btnRegister: isRegister,
action: {
if isRegister {
registerHandler.registerUser() {
permissionViewModel.getPermission()
}
} else {
loginHandler.userLogin() {
permissionViewModel.getPermission()
}
}
},
loginHandler: loginHandler,
registerHandler: registerHandler
)
.padding(.bottom, 5)
}
.frame(width:350,height:400)
.scrollContentBackground(.hidden)
.padding(.top, 50)
}
}
//
// RegisterViewModel.swift
// SpaceManager
//
// Created by Kuba Kromomołowski on 03/05/2024.
//
import Foundation
import Firebase
import FirebaseAuth
import FirebaseFirestore
class RegisterViewModel : ObservableObject {
@Published var email: String = ""
@Published var password: String = ""
@Published var repeatedPassword: String = ""
@Published var isFail: Bool = false
@Published var message: String = ""
func registerUser(completion: @escaping () -> Void) {
if(!validInput()){
return
}
Auth.auth().createUser(withEmail: email, password: password) { [weak self] res,
err in
guard let self = self else { return }
if let err = err {
self.isFail = true
self.message = "Błąd przy rejestracji \(err.localizedDescription)"
return
}
guard let userID = res?.user.uid else {
return
}
// DispatchQueue.main.async {
// print("Starting adding...")
self.addIntoDatabe(userID: userID, email: self.email)
// }
completion()
}
}
private func addIntoDatabe(userID: String, email: String) {
let newUser = User(uid: userID, email: email, permission: Permission.Admin, itemReads: [["Prop":2]],
numberOfAddedItem: 0, numberOfReadItem: 0)
let db = Firestore.firestore()
db.collection("users")
.document(userID)
.setData(["uid": newUser.uid, "email": newUser.email, "permission": newUser.permission.rawValue, "itemReads": newUser.itemReads, "numberOfAddedItem": newUser.numberOfAddedItem, "numberOfReadItem": newUser.numberOfReadItem])
print("User has been added into db")
}
}
Post
Replies
Boosts
Views
Activity
I am making application where I use navigation link to navigate from bottom menu to other views, and there is a problem when I change view a few times because views start stacking and when I set navigationBarBackButtonHidden(false) I can see on left side a lot of back button. This generate big problem because after changing views I got warning Abnormal number of gesture recognizer dependencies: 100. System performance may be affected. Please investigate reducing gesture recognizers and/or their dependencies. And after some more changes everything from screen is pushed down back button. Is there any solution to close previous view from we came?
There is code:
//
// BottomMenu.swift
// SpaceManager
//
// Created by Kuba Kromomołowski on 04/05/2024.
//
import SwiftUI
import Firebase
import FirebaseAuth
struct BottomMenu: View {
@StateObject var logManager = MainViewModel()
@StateObject var mvm = MenuViewModel()
@State var condition1: Bool = true
@State var condition2: Bool = false
@State var condition3: Bool = false
// @StateObject private var cameraViewModel = CameraViewModel()
var body: some View {
HStack{
Group{
//.navigationBarBackButtonHidden(true)
Spacer()
BtnMenu(btnText: "Dodaj",
btnIcon: "plus.app.fill",
destinationView:AnyView(LoggedMainView()),
isActive: condition1
)
Spacer()
BtnMenu(btnText: "Szukaj",
btnIcon: "magnifyingglass",
destinationView:AnyView(SearchView()),
isActive: condition2
)
Spacer()
BtnMenu(btnText: "Profil",
btnIcon: "person.crop.circle.fill",
destinationView:AnyView(ProfileView()),
isActive: condition3
)
Spacer()
}.padding(.bottom, 30)
.font(.system(size: 20))
}
}
}
#Preview {
BottomMenu()
}
//
// BtnMenu.swift
// SpaceManager
//
// Created by Kuba Kromomołowski on 04/05/2024.
//
import SwiftUI
struct BtnMenu: View {
var btnText: String
var btnIcon: String
var destinationView: AnyView
@State var isActive: Bool = true
var body: some View {
NavigationLink{
destinationView
} label: {
ZStack {
Text("\(Image(systemName: btnIcon)) \(btnText)")
}
}.disabled(isActive)
}
}