Eek! Can you help me with these bugs? Thanks!

Hi, my code has many different bugs, including an unknown attribute (@AppStorage), Value of type ‘Text’ has no member ‘navigationTitle’, and several Unable to infer complex closure return type; add explicit type to disambiguate. Can you please help me with this code? I’m trying to create a login page. I also have images too, and a color set that’s included. Thanks. Here it is with a picture and my code:


import SwiftUI
import LocalAuthentication

struct ContentView: View {
@AppStorage(“status”) var logged = false
var body: some View {

    NavigationView{
        
        if logged{
            
            Text("User Logged In...")
            .navigationTitle("Home")
            .navigationBarHidden(false)
        }
        else{
            
        Home()
            .preferredColorScheme(.dark)
            .navigationBarHidden(true)
        }
    }
}

}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

struct Home : View {

@State var userName = ""
@State var password = ""
//when first time user logged in via email store this for future biometric login...
@AppStorage("stored_User") var user = "STORED_EMAIL_ID"
@AppStorage("status") var logged = false

var body: some View{
  
    VStack{
        
        Spacer(minLength: 0)
        
        Image("logo")
        .resizable()
            .aspectRatio(contentMode: .fit)
            //Dynamic Frame...
            .padding(.horizontal, 35)
            .padding(.vertical)
        
        HStack{
            
            VStack(alignment: .leading, spacing: 12, content: {
                
                Text("Login")
                    .font(.title)
                    .fontWeight(.bold)
                    .foregroundColor(.white)
                
                Text("Please sign in to continue")
                    .foregroundColor(Color.white.opacity(0.5))
            })
            
            Spacer(minLength: 0)
            
        }
        .padding()
        .padding(.leading, 15)
        
        HStack{
            
            Image(systemName: "envelope")
                .font(.title2)
                .foregroundColor(.white)
                .frame(width: 35)
            
            TextField("EMAIL", text: $userName)
                .autocapitalization(.none)
                .foregroundColor(.white)
        }
        .padding()
        .background(Color.white.opacity(userName == "" ? 0 : 0.12))
        .cornerRadius(15)
        .padding(.horizontal)
        
        HStack{
            
            Image(systemName: "lock")
                .font(.title2)
                .foregroundColor(.white)
                .frame(width: 35)
            
            SecureField("PASSWORD", text: $password)
                .autocapitalization(.none)
                .foregroundColor(.white)
        }
        .padding()
        .background(Color.white.opacity(password == "" ? 0 : 0.12))
        .cornerRadius(15)
        .padding(.horizontal)
        .padding(.top)
        
        HStack(spacing: 15){
            Button(action: {}, label: {
            Text("LOGIN")
            .fontWeight(.heavy)
            .foregroundColor(.black)
            .padding(.vertical)
            .frame(width: UIScreen.main.bounds.width - 150)
            .background(Color("green"))
            .clipShape(Capsule())
                
            })
            .opacity(userName != "" && password != "" ? 1 : 0)
                .disabled(userName! = "" && password != "" ? false : true)
            
            if getBioMetricStatus(){
                
                Button(action: authenticateUser, label: {
                    
                    //getting biometrictype...
                    Image(systemName: LAContext().biometryType == .faceID ? "faceid" : "touchid")
                        .font(.title)
                        .foregroundColor(.black)
                        .padding()
                        .background(Color("green"))
                        .clipShape(Circle())
                })
            }
            
        }
        .padding(.top)
        //Forget Button...
        
        Button(action: {}, label: {
            Text("Forgot password?")
            .foregroundColor(Color("green"))
        })
            .padding(.top, 8)
        
        //SignUp...
        
        Spacer(minLength: 0)
        
        HStack(spacing: 5){
            
            Text("Don't have an account?")
                .foregroundColor(Color.white.opacity(0.6))
            
            Button(action: {}, label: {
                Text("Signup")
                .fontWeight(.heavy)
                .foregroundColor(Color("green"))
            })
           
        }
        .padding(.vertical)
        
    }
    .background(Color("bg"))
    .edgesIgnoringSafeArea(.all)
    .animation(.easeOut)
    
}

//Getting BioMetricType...

func getBioMetricStatus()->Bool{
    
    let scanner = LAContext()
    if userName == user && scanner.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: .none){
        
        return true
    }
    
    return false
}

//authenticate User...
mutating func authenticateUser(){
    
    let scanner = LAContext()
    scanner.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "To Unlock \(userName)") { (status, err) in
        if err != nil{
            print(err!.localizedDescription)
            return
            
        }
        //setting logged status as true...
        withAnimation(.easeOut){self.logged = true}
    }
    
}

}

What version of iOS is your project targeting? All of those errors are caused by using SwiftUI elements that are not available before iOS 14.

1 Like

I’m stuck on the same issue, with "Unknown attribute ‘AppStorage’. Did you find out what to do???

As indicated in the post from roosterboy, if you are using an earlier version of Xcode that is only capable of supporting iOS versions prior to iOS 14 or you have set your target build to earlier than iOS 14 then some methods and modifiers are not available to you.