Post

Replies

Boosts

Views

Activity

How can use model in view shortly?
I have small restaurans data in content view, but I want to use this data shortly inside of the homeview, I am typing   to use  @State var restaurants: [ Restaurant] but in other view I have HomeView, it is throw an error like     Cannot convert value of type '[Restaurant].Type' to expected argument type '[Restaurant]' for    HomeView( restaurants: [Restaurant]) line of code, I do not know what I missed? Any idea? struct HomeView: View { @State var restaurants = [ Restaurant(name: "Cafe Deadend", image: "cafedeadend"), Restaurant(name: "Homei", image: "homei"), Restaurant(name: "Teakha", image: "teakha"), Restaurant(name: "Cafe Loisl", image: "cafeloisl"), ] }
0
0
332
Feb ’22
Why I am not succes to register in my app in SwiftUI?
I am use firebase for my SwiftUI App, and I want to register with mail, but when I typing my mail it is throw an error like Oops! Something went wrong. Please try again. I do not know why? here is my code: StatusViewModel: class StatusViewModel: Identifiable, ObservableObject {       var title: String   var message: String       init(title: String = "", message: String = "") {     self.title = title     self.message = message   }       static var signUpSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been created successfully")   }       static var logInSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been logged in successfully")   }       static var errorStatus: StatusViewModel {     return StatusViewModel(title: "Error", message: "Oops! Something went wrong. Please try again.")   } } RegisterViewModel: import Foundation import Combine class RegisterViewModel: ObservableObject {   @Published var email: String = ""   @Published var password: String = ""   @Published var statusViewModel: StatusViewModel?   @Published var state: AppState       private var cancellableBag = Set<AnyCancellable>()   private let authAPI: AuthAPI       init(authAPI: AuthAPI, state: AppState) {     self.authAPI = authAPI     self.state = state   }       func signUp() {     authAPI.signUp(email: email, password: password)       .receive(on: RunLoop.main)       .map(resultMapper)       .replaceError(with: StatusViewModel.errorStatus)       .assign(to: \.statusViewModel, on: self)       .store(in: &cancellableBag)   } } extension RegisterViewModel {   private func resultMapper(with user: User?) -> StatusViewModel {     if user != nil {       state.currentUser = user       return StatusViewModel.signUpSuccessStatus     } else {       return StatusViewModel.errorStatus     }   } } struct Register: View {       @ObservedObject private var viewModel: RegisterViewModel   @State var pushActive = false         init(state: AppState) {           self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)           }   var body: some View {   NavigationLink(destination: HomeView(state: viewModel.state),                       isActive: self.$pushActive) {                 Button {                              self.viewModel.signUp()                                     } label: {                   Text("Register")                     .padding()                                     }               } } }
0
0
539
Mar ’22
How we can use the multiple register screen in SwiftUI for firebase?
I have multiple register screen in swiftUI, I did not understand how I will connect first register screen to second register screen, normally first register screen connect to main screen, but I want to connect first register screen to second register screen, and connect second register screen to main screen, how can I do it, any idea? StatusViewModel: class StatusViewModel: Identifiable, ObservableObject {       var title: String   var message: String       init(title: String = "", message: String = "") {     self.title = title     self.message = message   }       static var signUpSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been created successfully")   }       static var logInSuccessStatus: StatusViewModel {     return StatusViewModel(title: "Successful", message: "Your account has been logged in successfully")   }       static var errorStatus: StatusViewModel {     return StatusViewModel(title: "Error", message: "Oops! Something went wrong. Please try again.")   } } RegisterViewModel: import Foundation import Combine class RegisterViewModel: ObservableObject {   @Published var email: String = ""   @Published var password: String = ""   @Published var statusViewModel: StatusViewModel?   @Published var state: AppState       private var cancellableBag = Set<AnyCancellable>()   private let authAPI: AuthAPI       init(authAPI: AuthAPI, state: AppState) {     self.authAPI = authAPI     self.state = state   }       func signUp() {     authAPI.signUp(email: email, password: password)       .receive(on: RunLoop.main)       .map(resultMapper)       .replaceError(with: StatusViewModel.errorStatus)       .assign(to: \.statusViewModel, on: self)       .store(in: &cancellableBag)   } } extension RegisterViewModel {   private func resultMapper(with user: User?) -> StatusViewModel {     if user != nil {       state.currentUser = user       return StatusViewModel.signUpSuccessStatus     } else {       return StatusViewModel.errorStatus     }   } } first register screen: struct Register: View {       @ObservedObject private var viewModel: RegisterViewModel   @State var pushActive = false         init(state: AppState) {           self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)           }   var body: some View {  VStack(){                               TextField("Email Address",text:$viewModel.email)                 .autocapitalization(.none)                 .padding()                  HStack(spacing: 15){                     TextField("Password", text: $viewModel.password)                       .autocapitalization(.none)                                 }   NavigationLink(destination: HomeView(state: viewModel.state),                       isActive: self.$pushActive) {                 Button {                              self.viewModel.signUp()                                     } label: {                   Text("Register")                     .padding()                                     }               } } } second register screen: struct SecondRegister: View {   var body: some View {           GeometryReader { geometry in          ZStack{           VStack(alignment: .center, spacing: 3){                          TextField("First Name",text:self.$first_name)                 .autocapitalization(.none)                 .padding()               TextField("Last Name", text: self.$last_name)                 .autocapitalization(.none)                 .padding()                                 }                 Button {                 } label: {                   Text("Next")                     .padding()                    }             }           }.padding()           }.padding(.top,60)                 }     }
0
0
565
Mar ’22
Why I am able to register user info to firebase in SwiftUI App?
I have register screen and I am not able to register info to firebase, I put user info on simulator, but it just hold on on screen, and no any change on firebase, any idea? where I missed? import SwiftUI import Firebase struct Register: View {   @State var name = ""   @State var about = ""       @Binding var show : Bool   var body: some View {    VStack(alignment: .center, spacing: 3){                          TextField("Name",text:self.$name)                 .padding()                                       TextField(" about", text: self.$about)                 .padding()                if self.loading{                                          HStack{                                              Spacer()                                              Indicator()                                              Spacer()                     }                   }                                        else{                                 Button {                                       if self.name != "" && self.about != "" {                                                    self.loading.toggle()                     CreateUser(name: self.name, about: self.about) { (status) in                                                          if status{                                                              self.show.toggle()                                                       }                         }                       }                     else{                                                    self.alert.toggle()                                             }                 } label: {                   Text("Next")                     .padding()                    }               } } import Foundation import Firebase func CreateUser(name: String,about : String, completion : @escaping (Bool)-> Void){       let db = Firestore.firestore()       let storage = Storage.storage().reference()       let uid = Auth.auth().currentUser?.uid                   db.collection("users").document(uid!).setData(["name":name,"about":about, "uid":uid!]) { (err) in                   if err != nil{                       print((err?.localizedDescription)!)           return         }                   completion(true)                   UserDefaults.standard.set(true, forKey: "status")                   UserDefaults.standard.set(name, forKey: "UserName")                   NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil)       }     }
0
0
605
Mar ’22
How can I give the permission for WKWebView to access phone library?
I have a small app and I am using WKWebView for my app, so in WebView I have sign in, when I sign to WebView I have to import image, documents etc to WebView, so I have to use permission in my app, is it possible to apply WKWebView in below code? import SwiftUI import WebKit struct ContentView: View { var body: some View { ZStack{ WebView() } } } struct WebView: UIViewRepresentable { func makeUIView(context: Context) -> WKWebView { WKWebView(frame: .zero) } func updateUIView(_ view: WKWebView, context: UIViewRepresentableContext<WebView>) { let request = URLRequest(url: URL(string: "https://codepen.io/login")!) view.load(request) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .navigationBarHidden(true) } }
0
0
581
Jun ’22