Monday, December 25, 2023
HomeiOS Developmentios - Methods to correctly implement a world Consumer variable in SwiftUI

ios – Methods to correctly implement a world Consumer variable in SwiftUI


Im engaged on my first massive scale swiftUI undertaking and do not know the best way to correctly implement a world variable to retailer my energetic consumer in. In UIKit I may gloabally declare the variable as empty after which load it at runtime. Now with swiftUI I would like it to be loaded correctly and syntactically right to point out to preview of the UI.

I’ve a view SignUpView the place the brand new consumer is created, which is displayed in ContentView like so:

    //State vars
    @State var userNotSignedin = true
    
    var physique: some View {
        VinoMainView()
        /**
         when app is opened we should consider if a consumer exists
         if consumer exists : userNotSignedin = false
         else : userNotSignedIn = true
         */
            .fullScreenCover(isPresented: $userNotSignedin, content material: {
                NavigationStack {
                    ZStack {
                        LoginForm()
                        NavigationLink(
                            "Dont Have an Account? Signal-Up Right here",
                            vacation spot: SignUpView(userNotSignedin: $userNotSignedin)
                        )
                            .font(.customized("DMSerifDisplay-Common", measurement: 15))
                            .padding([.top], 300)
                    }
                }
            })
    }
    
    //verify if consumer exists in privateDB zone
    non-public func checkIfUserDoesntExists() -> Bool {
        let userDoesntExists = true
        
        return userDoesntExists
    }
}

I’ve tried utilizing completely different variations of @State vars from varied tutorials on-line and so they all make the previews not load so I am questioning what’s the right solution to implement a world var of UserObj in a swiftUI app.

Right here is my UserObj class:

public class UserObj: ObservableObject {
    var Fname: String
    var Lname: String
    var username: String
    var password: String
    var e mail: String
    var phoneNumber: String
    var pfp: UIImage
    var wines: [Wine]
    var recordID: String
    
    init(Fname: String, Lname: String, username: String, password: String, e mail: String, phoneNumber: String, pfp: UIImage, wines: [Wine], recordID: String = "") {
        self.Fname = Fname
        self.Lname = Lname
        self.username = username
        self.password = password
        self.e mail = e mail
        self.phoneNumber = phoneNumber
        self.pfp = pfp
        self.wines = wines
        self.recordID = recordID
    }
    
    init() {
        self.Fname = ""
        self.Lname = ""
        self.username = ""
        self.password = ""
        self.e mail = ""
        self.phoneNumber = ""
        self.pfp = UIImage()
        self.wines = []
        self.recordID = ""
    }
    
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments