Post

Replies

Boosts

Views

Activity

how do I remove the columns showing in the below pic if no data is available.
this below is the view which doesn't remove the columns after I click the delete button and it shows the data even after it is removed from the firestore unless relaunched the app. import SwiftUI import Firebase struct user:Identifiable{     @State var id:String=""     @State var productnm:String=""     @State var quan:String="" } class mainviewmodel:ObservableObject{     @Published var use = [user]()     init(){         fetchCurrentUser()     }      func fetchCurrentUser(){          guard let uid = Firebase.Auth.auth().currentUser?.uid else {             return         }          FirebaseManager.shared.firestore.collection("users").document(uid).collection("product").getDocuments{snapshot,error in              if error==nil{                              //no errors                 if let snapshot = snapshot{                     //update the user property in the main thread                 DispatchQueue.main.async {                     //                        //get all the documents and create user                                             self.use=snapshot.documents.map{ d in //map will iterate over array and perform code on each item                                                 //create an new user for each document returned                                                 return  user(id: d.documentID,productnm: d["product name"] as? String ?? "",                                                              quan: d["quantity"] as? String ?? "")                                             }                                         }                                                          }                  print("no data found")                                                   }                                 else{                                     print("no data found")                                 }         }     } } struct cart: View {     @ObservedObject var model=mainviewmodel()     @ObservedObject  var vm = mainviewmodel()     @State var productnm:String=""     @State var quantity:String=""     @State var address:String=""     @State var payment:String=""     var body: some View{         VStack{         HStack{             Text("Cart")             navcustom(content:                        Image(systemName: "cart"),col: .white)         Button(action: {vm.fetchCurrentUser()         }, label: {navcustom(content:                                 Image(systemName: "repeat.circle.fill"),col: .blue)})         }             List(model.use) {item in                     HStack(spacing: 16) {                         Image(systemName: "person.fill")                         .font(.system(size: 32))                             Text("\(item.productnm)")                             Text("\(item.quan)")                             }                 Button(action: {deleteuser(productnm: item.productnm, quan: item.quan, id: item.id)}, label: {Text("Delete")})                 Button(action: {if(address==""){Text("Enter the delivery address!").foregroundColor(.red)}else{buying(productnm: item.productnm, quantity: item.quan, address: address)}                     deleteuser(productnm: item.productnm, quan: item.quan, id: item.id)                 }, label: {Text("BUY")})                 }             Text("Delivery Address:")             TextField("", text:$address)                 .foregroundColor(.white)                 .frame(width: 295)                 .textFieldStyle(.roundedBorder)                  }     }     func deleteuser(productnm:String,quan:String,id:String){         guard let uid = Firebase.Auth.auth().currentUser?.uid else {            return        }         FirebaseManager.shared.firestore.collection("users").document(uid).collection("product").document(id).delete(){ err in             if let err = err {               print("Error removing document: \(err)")             }             else {               print("Document successfully removed!")                              }     }     }     func buying(productnm:String,quantity:String,address:String){             guard let uid = FirebaseManager.shared.auth.currentUser?.uid else { return }         let userData = ["user":uid,"product name":productnm,"quantity":quantity,"address":address]             FirebaseManager.shared.firestore.collection("purchase").document(uid).collection("product").addDocument(data: userData)             { err in                 if let err = err{                     print(err)                     return                 }             }     } } struct cart_Previews: PreviewProvider {     static var previews: some View {         Group {               cart()                 .environment(\.colorScheme, .dark)         }     } }
1
0
566
Mar ’22
My view moves down and down with every opening of that view.
This is the content view which moves down on the screen as I open it from different view. when I click top left button to open menu. The menu When I click the Home option from menu whole view moves down on screen. The whole view gets moved down on screen each time I open it. //the content view import SwiftUI struct ContentView: View {     var body: some View {                       NavigationView{                               ScrollView{                      Text("Men")                          .font(.system(size: 30, weight:.bold))                      .padding(.trailing, 320.0)                  ScrollView(.horizontal){                      HStack{                          NavigationLink(destination:mentshirt()){                          custom(content:Image("mentshirt"),over:"T-shirt",col: .black)                          }                          NavigationLink(destination:menjeans()){                          custom(content:Image("menjeans"),over:"Jeans",col: .black)                          }                          NavigationLink(destination:menjacket()){                          custom(content:Image("menjacket"),over: "Jacket",col: .black)                          }                      }                  }                      Text("Women")                          .font(.system(size: 30,weight: .bold))                          .padding(.trailing,280.0)                  ScrollView(.horizontal){                      HStack{                          NavigationLink(destination:womentshirt()){                          custom(content:Image("womentshirt"),over:"T-shirt",col: .black)                          }                          NavigationLink(destination:womenjeans()){                          custom(content:Image("womenjeans"),over:"Jeans",col: .black)                          }                          NavigationLink(destination:womenjacket()){                          custom(content:Image("womenjacket"),over:"Jacket",col: .black)                          }                      }                  }                      Text("Kids")                          .font(.system(size: 30,weight: .bold))                          .padding(.trailing,320.0)                  ScrollView(.horizontal){                      HStack{                          NavigationLink(destination:kidtshirt()){                              custom(content:Image("kidtshirt"),over:"T-shirt",col:.black)                      }                          NavigationLink(destination:kidjeans()){                          custom(content:Image("kidjeans"),over:"Jeans",col: .black)                          }                              NavigationLink(destination:kidjacket()){                          custom(content:Image("kidjacket"),over:"Jacket",col:.black)                              }                      }                  }                  }                  .navigationBarBackButtonHidden(true)                  .navigationBarItems(leading:                                          NavigationLink(                                          destination: clothlist()){                                                  navcustom(content:                                                             Image(systemName: "line.horizontal.3"),col: .white)                          },                      trailing:                              HStack{                      Image("logo")                          .resizable()                          .clipShape(Circle())                          .shadow(color:.white,radius: 10)                          .frame(width: 30, height: 30, alignment: .center)                              Spacer(minLength: 80)                          NavigationLink(destination: cart()){                              navcustom(content:                                         Image(systemName: "cart"),col: .white)                          }                          Spacer(minLength: 15)                              NavigationLink(destination: login()){                                  navcustom(content:Image(systemName: "person.crop.circle.fill"), col: .white)                              }                          }                  )              }.navigationBarBackButtonHidden(true)             .ignoresSafeArea()         } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         Group {               ContentView()                 .environment(\.colorScheme, .dark)         }     } } func custom(content:Image,over:String,col:Color) -> some View {     content         .resizable()         .overlay(Text(over).font(.system(size: 20,weight: .bold)).foregroundColor(col),alignment: .bottomLeading)         .frame(width: 400, height: 500, alignment: .center)         .padding(5)                        } func navcustom(content:Image,col:Color)-> some View {     content         .resizable()         .frame(width: 30, height: 30, alignment: .center)         .foregroundColor(col) } //the menu view from which I open content view import SwiftUI struct clothlist: View {     var body: some View {         List         {             NavigationLink(destination:ContentView())             {             Text(Image(systemName: "house"))+Text(" Home")             }             Text(Image(systemName: "person"))+Text(" Men")             NavigationLink(destination:menjeans())             {             Text("Jeans")             }             NavigationLink(destination:menjacket())             {             Text("Jacket")             }             NavigationLink(destination:mentshirt())             {             Text("Tshirt")             }             Text(Image(systemName: "person"))+Text(" Women")             NavigationLink(destination:womenjeans())             {             Text("Jeans")             }             NavigationLink(destination:womenjacket())             {             Text("Jacket")             }             NavigationLink(destination:womentshirt())             {             Text("Tshirt")             }             Group{             Text(Image(systemName: "person"))+Text(" Kids")             NavigationLink(destination:kidjeans())             {             Text("Jeans")             }             NavigationLink(destination:kidjacket())             {             Text("Jacket")             }             NavigationLink(destination:kidtshirt())             {             Text("Tshirt")             }             }         }         .navigationBarBackButtonHidden(true)     } } struct clothlist_Previews: PreviewProvider {     static var previews: some View {         clothlist()     } } how to stop the view from moving down on screen on every open?
0
0
1.2k
Mar ’22
Ive created a login view but as soon as I leave that view all the textfield and password field is empty.
I want the details entered in textfield and password should stay even after changing the view or closing the app and the person should be logged in even after he closes the app, Can anyone help me out? import SwiftUI import Firebase struct login: View {     @State var chec:String=""     @State var email:String=""     @State var navigated = false     @State var loggedin:Bool=false     @State var pass:String=""     @State private var secured:Bool=true     var body: some View     {                 VStack                 {                     if(loggedin==true)                     {                     Image("logo")                         .resizable()                         .clipShape(Circle())                         .shadow(color:.green,radius: 10)                         .frame(width: 200, height: 200, alignment: .center)                     }                     else                     {                         Image("logo")                             .resizable()                             .clipShape(Circle())                             .shadow(color:.red,radius: 10)                             .frame(width: 200, height: 200, alignment: .center)                     }                     Spacer(minLength: 50.0)                     Text(chec)                         .foregroundColor(.red)                     HStack                     {                         Text("E-mail:")                         TextField("", text:$email)                             .foregroundColor(.white)                             .frame(width: 275)                             .textFieldStyle(.roundedBorder)                             .autocapitalization(.none)                             .disableAutocorrection(true)                     }                         HStack                         {                         Text("Password:")                             if secured                             {                                 SecureField("",text:$pass)                                     .background(Color.black)                                     .foregroundColor(.white)                                     .textFieldStyle(.roundedBorder)                                     .autocapitalization(.none)                                     .disableAutocorrection(true)                             }                             else                             {                                 TextField("",text: $pass)                                     .background(Color.black)                                     .foregroundColor(.white)                                     .textFieldStyle(.roundedBorder)                                     .autocapitalization(.none)                                     .disableAutocorrection(true)                             }                             Button(action: {self.secured.toggle()})                             {                                 if secured                                 {                                     Image(systemName:"eye.slash")                                 }                                 else                                 {                                     Image(systemName:"eye")                                 }                             }.buttonStyle(BorderlessButtonStyle())                         }                     VStack{                         Button(action: {                             if(email==""&&pass=="")                             {                                 chec="Enter E-mail and Password"                             }                             else if(pass=="")                             {                                 chec="Enter Password"                             }                             else if(email=="")                             {                                 chec="Enter E-mail"                             }                             guard !email.isEmpty,!pass.isEmpty else                         {                             return                         }                             loginfunc()                         }){                             Text("Login")                         }                         NavigationLink(destination: signup(),label:{Text("Not Yet signed? Create new account")})                             .padding(.top, 3.0)                     }                     .padding()                     Spacer(minLength: 400)                 }                      }     func loginfunc(){         Auth.auth().signIn(withEmail: email, password: pass) { result, error in             if error != nil{                 print(error?.localizedDescription ?? "")                 loggedin=false                 chec="E-mail or Password wrong!"             }else {                 print("success")                 loggedin=true             }             if(loggedin==true)             {                 chec=""                 print("wow so nice to get work done")             }         }     } } //} struct ButtonView: View {     var buttext:String     var body: some View {         Text(buttext)         .frame(width: 200, height: 100, alignment: .center)         .background(Color.black)         .foregroundColor(Color.white)     } } struct login_Previews: PreviewProvider {     static var previews: some View {         login()             .environment(\.colorScheme, .dark)     } }
1
0
787
Mar ’22
I tried using multilinetextalignment but my text is not aligning on left of iPhone screen, what is the reason for it?
import SwiftUI struct lastview: View {     var img:UIImage     var texty:String     var body: some View {         ScrollView(.vertical){         Image(uiImage: img)             .resizable()             .frame(width: 500, height: 500, alignment: .center)             Text(texty)                 .multilineTextAlignment(.leading)                          }     } }
1
0
998
Mar ’22
I want the image clicked on the first view as main image on next view, How to do it?
I want the image I clicked in the first view to the last view as main image. First View Clicked on image Last View Code for it is below: //This is the First View import SwiftUI struct kidtshirt: View {     var clothimages:[UIImage] =         [UIImage(named:"IMG_9981")!,         UIImage(named:"IMG_9985")!,         UIImage(named:"IMG_9987")!]     var tshirt:[String]=["PLAIN T-SHIRT\n₹590.00","PRINTED T-SHIRT\n₹790.00","JACQUARD DAISY PRINT T-SHIRT\n₹1,090.00"]     let layout=[GridItem(.flexible()),GridItem(.flexible())]     var body: some View     { //        NavigationView //        {             ScrollView(.vertical)             {             LazyVGrid(columns: layout,spacing: 2)                 {                 ForEach(Array(zip(clothimages,tshirt)), id: .0)                     {                     (imager,texter) in                         NavigationLink(destination:lastview()){maincustom(content: Image(uiImage:imager), text: texter)                         }                     }                     .navigationBarTitle("Kid Tshirt")                 }             }             .navigationBarBackButtonHidden(true)                 .navigationBarItems(leading:                                         NavigationLink(                                         destination: clothlist()){                                                 navcustom(content:                                                            Image(systemName: "line.horizontal.3"),col: .white)                                         })         }      //} } struct kidtshirt_Previews: PreviewProvider {     static var previews: some View {         kidtshirt()     } } //This is the Last View import SwiftUI struct lastview: View {     var body: some View {         Image("IMG_9981")             .resizable()             .frame(width: 500, height: 500, alignment: .center)     } } struct lastview_Previews: PreviewProvider {     static var previews: some View {         lastview()     } }
0
0
542
Feb ’22
I used array to print image. but I also want to print text with the images using array how can I use it ,like I want to use same tray but want to print different text with their images using the same array like 2D array.
import SwiftUI struct menjeans: View {     var menje:[UIImage] =         [UIImage(named:"IMG_9917")!,         UIImage(named:"IMG_9920")!,         UIImage(named:"IMG_9923")!]     let layout=[GridItem(.flexible()),GridItem(.flexible())]     var body: some View     {         NavigationView         {             ScrollView(.vertical)             {             LazyVGrid(columns: layout,spacing: 2)                 {                 ForEach(menje, id: .self)                     {                     imager in                         maincustom(content: Image(uiImage:imager), text: "df")                     }                     .navigationBarTitle("Men")                 }             }         }     } } struct menjeans_Previews: PreviewProvider {     static var previews: some View {         menjeans()     } }
0
0
974
Feb ’22
Why do i get this error to conform a view
// //  ContentView.swift //  shop // //  Created by Cloud Patel on 26/12/21. // import SwiftUI     func trying()     {         for el in clothimages         {             print(el)         }     } struct ContentView: View {     var clothimages:[UIImage] =         [UIImage(named:"menjacket")!,         UIImage(named:"menjeans")!,         UIImage(named:"mentshirt")!]     var body: some View {              NavigationView{                               ScrollView{                      Text("Men")                          .font(.system(size: 30, weight:.bold))                      .padding(.trailing, 320.0)                  ScrollView(.horizontal){                      HStack{ //this is where I get error //Type '()' cannot conform to 'View'                                                    trying() //                         custom(content:Image("mentshirt"),over:"T-shirt",col: .black) //                         custom(content:Image("menjeans"),over:"Jeans",col: .black) //                         custom(content:Image("menjacket"),over: "Jacket",col: .black)                      }                  }                      Text("Women")                          .font(.system(size: 30,weight: .bold))                          .padding(.trailing,280.0)                  ScrollView(.horizontal){                      HStack{                          custom(content:Image("womentshirt"),over:"T-shirt",col: .black)                          custom(content:Image("womenjeans"),over:"Jeans",col: .black)                          custom(content:Image("womenjacket"),over:"Jacket",col: .black)                      }                  }                      Text("Kids")                          .font(.system(size: 30,weight: .bold))                          .padding(.trailing,320.0)                  ScrollView(.horizontal){                      HStack{                          NavigationLink(destination:login()){                              custom(content:Image("kidtshirt"),over:"T-shirt",col:.black)                      }                          custom(content:Image("kidjeans"),over:"Jeans",col: .black)                          custom(content:Image("kidjacket"),over:"Jacket",col:.black)                      }                  }                  }                  .navigationBarItems(leading:                                          NavigationLink(                                          destination: edit()){                                                  navcustom(content:                                                             Image(systemName: "line.horizontal.3"),col: .white)                          },                      trailing:                              HStack{                      navcustom(content:                                 Image(systemName: "indianrupeesign.circle.fill"),col: .white)                              Spacer(minLength: 80)                          NavigationLink(destination: cart()){                              navcustom(content:                                         Image(systemName: "cart"),col: .white)                          }                          Spacer(minLength: 15)                              NavigationLink(destination: logger()){                                  navcustom(content:Image(systemName: "person.crop.circle.fill"), col: .white)                              }                          }                  )              }                       } }                                           func logger() -> some View{         var userlogg=false         if userlogg{             return AnyView(settings())         }         else{             return AnyView(login())         }     }          struct ContentView_Previews: PreviewProvider {     static var previews: some View {         Group {               ContentView() //                .environment(.colorScheme, .dark)         }     } } func custom(content:Image,over:String,col:Color) -> some View {     content         .resizable()         .overlay(Text(over).font(.system(size: 20,weight: .bold)).foregroundColor(col),alignment: .bottomLeading)         .frame(width: 400, height: 500, alignment: .center)         .padding(5)                        } func navcustom(content:Image,col:Color)-> some View {     content         .resizable()         .frame(width: 30, height: 30, alignment: /@START_MENU_TOKEN@/.center/@END_MENU_TOKEN@/)         .foregroundColor(col) } //class watchlog:ObservableObject{ //    @Published var userlogg=false //} //struct logging{ //    func logger() -> some View{ //        var userlogg=true //        if userlogg{ //            return AnyView(settings()) //        } //        else{ //            return AnyView(login()) //        } //    } //} // even if I use the function a structure I get this error struct nonsense:View{     var body: some View     {         func trying(). //Closure containing a declaration cannot be used with result builder 'ViewBuilder'         {             for el in clothimages             {                 print(el)             }         }     } }
0
0
462
Jan ’22