Education

RSS for tag

Teach students of all ages to code in Swift using a variety of resources in your curriculum.

Posts under Education tag

108 Posts

Post

Replies

Boosts

Views

Activity

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.4k
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
1.1k
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
1.2k
Mar ’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
1.2k
Feb ’22
"code in Objective-C to maintain"
I am learning Swift and when I was casually browsing for job openings to see what the employers expect one thing caught my eyes. It says something like, In addition to Swift, "code in Objective-C to maintain" What does that mean? If I learn Swift and have a good understanding, will learning and using Obj-C be easier? Is it a common requirement for iOS/macOS developers? Appreciate your time!
1
0
698
Jan ’22
Developer Site Changes Doc?
There are many nice changes here in recent years. Is there a document or page that outlines and explains the changes to the Developer portal that resulted in the excellent Document Archive no longer being maintained? https://developer.apple.com/library/archive/navigation/# Is there currently a reliable way to search for all of the newer sample code and documents within one list/view?
0
0
752
Nov ’21
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?
Replies
0
Boosts
0
Views
1.4k
Activity
Mar ’22
Resource recommendations for beginners?
Hi friends. I'm new around here and just migrated from Windows to macOS. I started working on iOS development with Swift. So if you have any study resource suggestions for beginners, can you share them? I am open to all resources such as documents, websites, videos.
Replies
0
Boosts
0
Views
590
Activity
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)     } }
Replies
1
Boosts
0
Views
1.1k
Activity
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)                          }     } }
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’22
Swift Challenge
Hi guys I want to participate in the Swift Student Challenge this year. Any suggestions on how to prepare for it?
Replies
1
Boosts
0
Views
915
Activity
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()     } }
Replies
0
Boosts
0
Views
1.2k
Activity
Feb ’22
"code in Objective-C to maintain"
I am learning Swift and when I was casually browsing for job openings to see what the employers expect one thing caught my eyes. It says something like, In addition to Swift, "code in Objective-C to maintain" What does that mean? If I learn Swift and have a good understanding, will learning and using Obj-C be easier? Is it a common requirement for iOS/macOS developers? Appreciate your time!
Replies
1
Boosts
0
Views
698
Activity
Jan ’22
Developer Site Changes Doc?
There are many nice changes here in recent years. Is there a document or page that outlines and explains the changes to the Developer portal that resulted in the excellent Document Archive no longer being maintained? https://developer.apple.com/library/archive/navigation/# Is there currently a reliable way to search for all of the newer sample code and documents within one list/view?
Replies
0
Boosts
0
Views
752
Activity
Nov ’21