Post

Replies

Boosts

Views

Activity

Instance member 'success' of type 'SignUp' cannot be used on instance of nested type 'SignUp.ContentView_Previews'
Code: //  Login.swift //  test // //  Created by David Csontos on 3/10/21. // // //  ContentView.swift //  test // //  Created by David Csontos on 2/10/21. // import SwiftUI import FirebaseAuth import FirebaseDatabase struct SignUp: View {          @State var Value: String = ""     @State var username: String = ""     @State var email: String = ""     @State var password: String = ""     @State var success = false          var body: some View {                           NavigationView{             ZStack {                                  LinearGradient(gradient: Gradient(colors: [Color.blue, Color.white]), startPoint: .topLeading, endPoint: .bottomTrailing)                     .ignoresSafeArea()                                  Rectangle()                     .fill(Color.white)                     .frame(width: 300, height: 550)                     .cornerRadius(10)                                                   VStack(spacing: 30){                     Image(systemName: "bitcoinsign.circle")                         .font(.system(size: 70, weight: .medium))                         .padding()                     TextField("Username", text: $username)                         .frame(width: 200, height: 30)                         .padding()                         .overlay(RoundedRectangle(cornerRadius: 10.0).strokeBorder(Color.blue, style: StrokeStyle(lineWidth: 2.0)))                         .foregroundColor(.green)                     TextField("Email", text: $email)                         .frame(width: 200, height: 30)                         .padding()                         .overlay(RoundedRectangle(cornerRadius: 10.0).strokeBorder(Color.blue, style: StrokeStyle(lineWidth: 2.0)))                         .foregroundColor(.green)                     TextField("Password", text: $password)                         .frame(width: 200, height: 30)                         .padding()                         .overlay(RoundedRectangle(cornerRadius: 10.0).strokeBorder(Color.blue, style: StrokeStyle(lineWidth: 2.0)))                         .foregroundColor(.green)                     Button(action: {                         createUser(withEmail: email, password: password, username: username)                         success = true                                                                   }, label: {                             Text("Sign Up")                                 .frame(width: 200, height: 20, alignment: .center)                                 .padding()                                 .background(Color.blue)                                 .foregroundColor(Color.white)                                 .cornerRadius(15)                         })                                                                            }             }         }                           } struct ContentView_Previews: PreviewProvider {          static var previews: some View {         if success == false {             SignUp()         }         else{             Login()         }     } } } func createUser(withEmail email: String, password: String, username: String){          Auth.auth().createUser(withEmail: email, password: password) { (result, error) in                  if let error = error {             print("Failed to sign user up", error.localizedDescription)             return         }                  else{             guard let uid = result?.user.uid else { return}                          let values = ["email": email, "username":username]                          Database.database().reference().child(uid).child("users").updateChildValues(values, withCompletionBlock: { (error, ref) in                                  if let error = error {                                          print("failed to update databse values with error", error.localizedDescription)                                          return                 }                 else {                     print("user successfully created..")                                          }                                                                                                  })         }              } } When I try to access the 'success' variable in 'struct ContentView_Previews' it throws the error: Instance member 'success' of type 'SignUp' cannot be used on instance of nested type 'SignUp.ContentView_Previews'. Is there a reason that this is happening/am I missing a simple concept. Any help will be appreciated.
1
0
456
Oct ’21
How to access variable in separate function
code: import SwiftUI struct practise: View {     @State var value = false          var body: some View {         Text("Hello, World!")     } } struct practise_Previews: PreviewProvider {     static var previews: some View {         practise()     } } func changevalue(){     //Change Value here } How am I able to change the value of 'value', within the change value() function.
1
0
317
Oct ’21
Unexpected non-void return value in void function error in function
code: func returnusername(){     guard let uid = Auth.auth().currentUser?.uid else { return  }     guard (Auth.auth().currentUser?.uid) != nil else {return}      Database.database().reference().child(uid).child("users").child("username").observeSingleEvent(of: .value){ (snapshot) in       guard let username = snapshot.value as? String else {return}       return username } } When I try return username it outputs the following error: Unexpected non-void return value in void function. What am I doing wrong?
2
0
4.1k
Oct ’21