Post

Replies

Boosts

Views

Created

problem with ForEach loop
when I'm using for each loop(using repeat command) instead of printing 5 items it is printing 10 times, it always doubles my command it is my code NavigationView {             ScrollView {                 ScrollView(.horizontal , showsIndicators: false){                     HStack(spacing: -10){                         ForEach(0..<5) { item in                             NavigationLink(destination: DetailView()) {                                 CardView()                             CardView()
2
0
1.2k
Aug ’22
Value of type ' Module<Wallet_App>' has no subscript please check the below code
import SwiftUI struct List_View: View {     var Wallet : Wallet_Data     var body: some View {                      ZStack {                 ListRectShape()                     .fill(Color.background)                 .frame(width: 368, height: 75)                 Wallet.image                     .padding(.trailing, 280.0)                 Text("Amazon")                     .font(.title3)                     .fontWeight(.light)                     .foregroundColor(Color.white)                     .multilineTextAlignment(.leading)                     .padding(.top, -25.0)                     .padding(.trailing, 125.0)                 Text("Augest 10 2022")                     .font(.body)                     .fontWeight(.light)                     .foregroundColor(Color.white)                     .padding(.trailing, 78.0)                     .padding(.top, 21.0)                 ListRectShape()                     .fill(Color.background)                     .frame(width: 83, height: 33)                     .border(Color.white)                     .padding(.leading, 225.0)                 Text("$109.08")                     .foregroundColor(Color.white)                     .padding(.leading, 225.0)                                                                }                  ZStack {             ListRectShape()                 .fill(Color.background)             .frame(width: 368, height: 75)             Image("Apple WC")                 .padding(.trailing, 280.0)             Text("Apple")                 .font(.title3)                 .fontWeight(.light)                 .foregroundColor(Color.white)                 .multilineTextAlignment(.leading)                 .padding(.top, -22.0)                 .padding(.trailing, 145.0)             Text("Augest 10 2022")                 .font(.body)                 .fontWeight(.light)                 .foregroundColor(Color.white)                 .padding(.trailing, 78.0)                 .padding(.top, 21.0)             ListRectShape()                 .fill(Color.background)                 .frame(width: 83, height: 33)                 .border(Color.white)                 .padding(.leading, 225.0)             Text("$1000.00")                 .foregroundColor(Color.white)                 .padding(.leading, 225.0)                               }                  } } struct List_View_Previews: PreviewProvider {     static var previews: some View {         List_View(Wallet: Wallet_App[0]) // here is were I'm getting an error     } } //this is my ModelData were I'm trying to load my json file import Foundation import Combine final class ModelData : ObservableObject{   var Wallet_App: [Wallet_Data] = load("Contents.json") } func load<T: Decodable>(_ filename: String) -> T {     let data: Data     guard let file = Bundle.main.url(forResource: filename, withExtension: nil)         else {             fatalError("Couldn't find (filename) in main bundle.")     }     do {         data = try Data(contentsOf: file)     } catch {         fatalError("Couldn't load (filename) from main bundle:\n(error)")     }     do {         let decoder = JSONDecoder()         return try decoder.decode(T.self, from: data)     } catch {         fatalError("Couldn't parse (filename) as (T.self):\n(error)")     } }
2
0
747
Aug ’22
How to add other(CardView) Another Swift UI file in Button
Button(action:                     CardView() //here it show an error how to add the CardView Swift ui file in this button //                 ) {                         Image(systemName: "creditcard")                         .resizable()                         .foregroundColor(Color("Icon Color"))                         .frame(width:24, height: 24)                                        }                 .padding(.top, 825.0)                 .padding(.trailing, 125.0)
12
0
2.1k
Aug ’22
I have two sets of code which are literally same but only one code set works and another doesn't
import Foundation enum VideoDetails: String, CaseIterable{     case Nature , Food , Animals , Travel } struct ResponseBody: Decodable {     var page: Int     var perPage: Int     var totalResults: Int     var url: String     var videos: [Video]      }      struct Video: Identifiable, Decodable{     var id: Int     var image: String     var duration: Int     var user: User     var videofiles: [VideoFile]                        struct User: Identifiable, Decodable {       var id: Int       var name: String       var url: String    }                 struct VideoFile: Identifiable, Decodable {       var id: Int       var quality: String       var fileType: String       var link: String    }  }   //this one doesn't work but the below code works perfectly can anyone why it is happening import Foundation enum VideoDetails: String, CaseIterable{     case Nature , Food , Animals , Travel } struct Video: Identifiable, Decodable {     var id: Int     var image: String     var duration: Int     var user: User     var videoFiles: [VideoFile]          struct User: Identifiable, Decodable {         var id: Int         var name: String         var url: String     }          struct VideoFile: Identifiable, Decodable {         var id: Int         var quality: String         var fileType: String         var link: String     } }
3
0
616
Sep ’22
How to open settings programmatically in Swift
import SwiftUI struct ButtonUI: View {     var body: some View {                      ZStack {                                  Color.white             RoundedRectangle(cornerRadius: 50)                     .fill(.blue)                     .frame(width: 250, height: 75, alignment: .center)                                  Text("Enable Location")                     .font(.title3)                     .fontWeight(.bold)                     .foregroundColor(Color.white)                              }             .offset(x: 0, y: 300)     } } struct ButtonUI_Previews: PreviewProvider {     static var previews: some View {         ButtonUI()     } } // I have used this code to create a button like shape in Xcode how to do i make it work like open the location settings in iPhone // it should work like a button to open the location settings in iPhone
3
0
7.3k
Oct ’22
Build Error due o info.plist
this is the error I'm getting building the project Build input file cannot be found: '/Users/nsame/Desktop/Xcode Files/Login FireBase/Login FireBase/Login FireBase/Info.plist'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? what does it means I have already gone through several forms before posting it can anyone say what should I do
1
0
7.5k
Oct ’22
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value .... what im I doing wrong
//  OTPViewController.swift //  FinalBookingApp // //  Created by Makwin Santhosh K on 19/10/22. // import UIKit import FirebaseAuth import Firebase import FirebaseCore class OTPViewController: UIViewController {          @IBOutlet weak var OTPLabel: UILabel!          @IBOutlet weak var EnterOTPLabel: UILabel!     @IBOutlet weak var MailTextField : UITextField!     @IBOutlet weak var PasswordTextField: UITextField!     @IBOutlet weak var EnterOTPTextField: UITextField!     @IBOutlet weak var VerifyButton: UIButton!     @IBOutlet weak var ErrorLabel : UILabel!               override func viewDidLoad() {         super.viewDidLoad()                  // Do any additional setup after loading the view.     }     // check the data validate Things     func validateFields() -> String?{         if PasswordTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" //   // im getting error in this error saying "Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"         {             return "Please enter the password without the BlankSpaces"         }         let cleanedPassword = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)         if Helpers.isPasswordValid(cleanedPassword) == false{             //Password wasn't secure enough             return "Please make sure your password is at least 8 characters, contains a special character and a number."         }         return nil     }          /*      // MARK: - Navigation            // In a storyboard-based application, you will often want to do a little preparation before navigation      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {      // Get the new view controller using segue.destination.      // Pass the selected object to the new view controller.      }      */          @IBAction func ButtonTapped(_ sender: Any) {         let error = validateFields()                  if error != nil {                          // There's something wrong with the fields, show error message             showError(error!)         }         else {             let Email = MailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)             let Password = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)             //MARK: Create a User             Auth.auth().createUser(withEmail: Email, password: Password){(result,err) in                 if err != nil {                                          // There was an error creating the user                     self.showError("Error creating user")                 }                 else {                                          let db = Firestore.firestore()                                                               db.collection("Users").addDocument(data: ["mail" : Email, "uid" : result!.user.uid])                 }             }             self.TransistiontoHome()         }              }                  func showError(_ message : String){             ErrorLabel.text = message             ErrorLabel.alpha = 1         }         func TransistiontoHome() {                      }          }
2
0
1.4k
Nov ’22
Publishing changes from within view updates is not allowed, this will cause undefined behavior.
Im building the small Map View by accessing the Users Location From the App Im getting this Error in Xcode 14 in Purple Color there is no error in this Code side it shows only while running in this simulator also according to the error My Location is not updating to it Can any 1 say where am I going wrong below is my code //  MapUIView.swift //  Login_Via_SwiftUI // //  Created by Makwin Santhosh K on 10/11/22. // import SwiftUI import MapKit import CoreLocationUI struct MapUIView: View {     @StateObject private var ViewModel = ContentViewModal()     var body: some View {         ZStack(alignment: .bottom) {             Map(coordinateRegion: $ViewModel.region, showsUserLocation: true)                 .ignoresSafeArea()                                       LocationButton(.currentLocation){                 ViewModel.requestUserLocationForOnce()             }             .foregroundColor(.white)             .cornerRadius(8)             .padding()                      }     } } struct MapUIView_Previews: PreviewProvider {     static var previews: some View {         MapUIView()                  } } final class ContentViewModal: NSObject, ObservableObject, CLLocationManagerDelegate{          @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 40, longitude: 120), span: MKCoordinateSpan(latitudeDelta: 100, longitudeDelta: 100))          let locationManager = CLLocationManager()          override init() {         super.init()         locationManager.delegate = self     }               func requestUserLocationForOnce() {         locationManager.requestLocation()     }          func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {         guard let latestLocation = locations.first else{             //show error             return         }         DispatchQueue.main.async {             self.region = MKCoordinateRegion(center: latestLocation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))         }     }     func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {         print(error.localizedDescription)     } }
4
0
3.2k
Nov ’22
Button to navigate through SwiftUI Views
this is my code I need my toolBar buttons to navigate to other SwiftUi views what should I write in button action { } to open the other SwiftUi View //  SwiftLoginView.swift //  Login FireBase // //  Created by Makwin Santhosh K on 08/11/22. // import SwiftUI import MapKit import CoreLocationUI struct OverallView: View {     var body: some View{                  NavigationView {             ZStack{                                  ToolBarShape()                     .frame(width: 400,height: 110)                     .foregroundColor(.white)                     .shadow(radius: 6)                     .offset(x : 0, y: 410)                                                     .toolbar {                         ToolbarItemGroup(placement: .bottomBar){                             //MARK: Button Home                             Button(action :{                                                              }, label:{                                 VStack {                                     Image(systemName: "house")                                     Text("Home")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Money                             Button(action :{                                                            },label:{                                 VStack {                                     Image(systemName: "dollarsign")                                     Text("Money")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Home                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "person")                                     Text("Help")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                             //MARK: Button Home                             Spacer()                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "menubar.rectangle")                                     Text("More")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                                                                                   }                                              }             }         }     } }      struct MapUView: View {     @StateObject public var ViewModel = ContentViewModal()          var body: some View {         ZStack(alignment: .bottom) {             AreaMap(region: $ViewModel.region)                          LocationButton(.currentLocation){                 ViewModel.requestUserLocationForOnce()             }             .foregroundColor(.white)             .cornerRadius(8)              }     }                                   struct AreaMap: View {         @Binding var region: MKCoordinateRegion                  var body: some View {             let binding = Binding(                 get: { self.region },                 set: { newValue in                     DispatchQueue.main.async {                         self.region = newValue                     }                 }             )             return Map(coordinateRegion: binding, showsUserLocation: true)                 .ignoresSafeArea()         }     }               final class ContenViewModal: NSObject, ObservableObject, CLLocationManagerDelegate{         @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 20, longitude: 90), span: MKCoordinateSpan(latitudeDelta: 100, longitudeDelta: 100))         let locationManager = CLLocationManager()                  override init() {             super.init()             locationManager.delegate = self         }                  func requestUserLocationForOnce() {             locationManager.requestLocation()         }                  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {             guard let latestLocation = locations.first else {                 //show error                 return             }             self.region = MKCoordinateRegion(center: latestLocation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))         }                  func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {             print(error.localizedDescription)         }     } } struct OverallView_Previews: PreviewProvider {     static var previews: some View {         OverallView()     } }
5
0
5.2k
Nov ’22
problem with ForEach loop
when I'm using for each loop(using repeat command) instead of printing 5 items it is printing 10 times, it always doubles my command it is my code NavigationView {             ScrollView {                 ScrollView(.horizontal , showsIndicators: false){                     HStack(spacing: -10){                         ForEach(0..<5) { item in                             NavigationLink(destination: DetailView()) {                                 CardView()                             CardView()
Replies
2
Boosts
0
Views
1.2k
Activity
Aug ’22
Value of type ' Module<Wallet_App>' has no subscript please check the below code
import SwiftUI struct List_View: View {     var Wallet : Wallet_Data     var body: some View {                      ZStack {                 ListRectShape()                     .fill(Color.background)                 .frame(width: 368, height: 75)                 Wallet.image                     .padding(.trailing, 280.0)                 Text("Amazon")                     .font(.title3)                     .fontWeight(.light)                     .foregroundColor(Color.white)                     .multilineTextAlignment(.leading)                     .padding(.top, -25.0)                     .padding(.trailing, 125.0)                 Text("Augest 10 2022")                     .font(.body)                     .fontWeight(.light)                     .foregroundColor(Color.white)                     .padding(.trailing, 78.0)                     .padding(.top, 21.0)                 ListRectShape()                     .fill(Color.background)                     .frame(width: 83, height: 33)                     .border(Color.white)                     .padding(.leading, 225.0)                 Text("$109.08")                     .foregroundColor(Color.white)                     .padding(.leading, 225.0)                                                                }                  ZStack {             ListRectShape()                 .fill(Color.background)             .frame(width: 368, height: 75)             Image("Apple WC")                 .padding(.trailing, 280.0)             Text("Apple")                 .font(.title3)                 .fontWeight(.light)                 .foregroundColor(Color.white)                 .multilineTextAlignment(.leading)                 .padding(.top, -22.0)                 .padding(.trailing, 145.0)             Text("Augest 10 2022")                 .font(.body)                 .fontWeight(.light)                 .foregroundColor(Color.white)                 .padding(.trailing, 78.0)                 .padding(.top, 21.0)             ListRectShape()                 .fill(Color.background)                 .frame(width: 83, height: 33)                 .border(Color.white)                 .padding(.leading, 225.0)             Text("$1000.00")                 .foregroundColor(Color.white)                 .padding(.leading, 225.0)                               }                  } } struct List_View_Previews: PreviewProvider {     static var previews: some View {         List_View(Wallet: Wallet_App[0]) // here is were I'm getting an error     } } //this is my ModelData were I'm trying to load my json file import Foundation import Combine final class ModelData : ObservableObject{   var Wallet_App: [Wallet_Data] = load("Contents.json") } func load<T: Decodable>(_ filename: String) -> T {     let data: Data     guard let file = Bundle.main.url(forResource: filename, withExtension: nil)         else {             fatalError("Couldn't find (filename) in main bundle.")     }     do {         data = try Data(contentsOf: file)     } catch {         fatalError("Couldn't load (filename) from main bundle:\n(error)")     }     do {         let decoder = JSONDecoder()         return try decoder.decode(T.self, from: data)     } catch {         fatalError("Couldn't parse (filename) as (T.self):\n(error)")     } }
Replies
2
Boosts
0
Views
747
Activity
Aug ’22
how can I stack one over other, please anyone help me solve
like the below Figma file
Replies
1
Boosts
0
Views
489
Activity
Aug ’22
How to add other(CardView) Another Swift UI file in Button
Button(action:                     CardView() //here it show an error how to add the CardView Swift ui file in this button //                 ) {                         Image(systemName: "creditcard")                         .resizable()                         .foregroundColor(Color("Icon Color"))                         .frame(width:24, height: 24)                                        }                 .padding(.top, 825.0)                 .padding(.trailing, 125.0)
Replies
12
Boosts
0
Views
2.1k
Activity
Aug ’22
How to learn Animation in swift with Cartoon
Any reources available to learn advanced animation from scratch it would be helpful if someone mentions any resiurces thank you
Replies
0
Boosts
0
Views
1.7k
Activity
Sep ’22
how to view controller in simulator
I'm trying to add a video in viewController and there is a minor issue. I'm not able view video them in simulator can any one explain how to view viewController in simulator. when I click the play button it only displays the ContentView
Replies
2
Boosts
0
Views
822
Activity
Sep ’22
I have two sets of code which are literally same but only one code set works and another doesn't
import Foundation enum VideoDetails: String, CaseIterable{     case Nature , Food , Animals , Travel } struct ResponseBody: Decodable {     var page: Int     var perPage: Int     var totalResults: Int     var url: String     var videos: [Video]      }      struct Video: Identifiable, Decodable{     var id: Int     var image: String     var duration: Int     var user: User     var videofiles: [VideoFile]                        struct User: Identifiable, Decodable {       var id: Int       var name: String       var url: String    }                 struct VideoFile: Identifiable, Decodable {       var id: Int       var quality: String       var fileType: String       var link: String    }  }   //this one doesn't work but the below code works perfectly can anyone why it is happening import Foundation enum VideoDetails: String, CaseIterable{     case Nature , Food , Animals , Travel } struct Video: Identifiable, Decodable {     var id: Int     var image: String     var duration: Int     var user: User     var videoFiles: [VideoFile]          struct User: Identifiable, Decodable {         var id: Int         var name: String         var url: String     }          struct VideoFile: Identifiable, Decodable {         var id: Int         var quality: String         var fileType: String         var link: String     } }
Replies
3
Boosts
0
Views
616
Activity
Sep ’22
How to open settings programmatically in Swift
import SwiftUI struct ButtonUI: View {     var body: some View {                      ZStack {                                  Color.white             RoundedRectangle(cornerRadius: 50)                     .fill(.blue)                     .frame(width: 250, height: 75, alignment: .center)                                  Text("Enable Location")                     .font(.title3)                     .fontWeight(.bold)                     .foregroundColor(Color.white)                              }             .offset(x: 0, y: 300)     } } struct ButtonUI_Previews: PreviewProvider {     static var previews: some View {         ButtonUI()     } } // I have used this code to create a button like shape in Xcode how to do i make it work like open the location settings in iPhone // it should work like a button to open the location settings in iPhone
Replies
3
Boosts
0
Views
7.3k
Activity
Oct ’22
The Assistant doesn't show up for View Controller
I have just started to learn Storyboard While I was Creating the View Controller, the Assistant doesn't open up to opens up only for navigation controller. I have like 2 View Controller, Assistant doesn't showing up for those two of them. can anyone point out where it I make a mistake.
Replies
2
Boosts
0
Views
2k
Activity
Oct ’22
Build Error due o info.plist
this is the error I'm getting building the project Build input file cannot be found: '/Users/nsame/Desktop/Xcode Files/Login FireBase/Login FireBase/Login FireBase/Info.plist'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? what does it means I have already gone through several forms before posting it can anyone say what should I do
Replies
1
Boosts
0
Views
7.5k
Activity
Oct ’22
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value .... what im I doing wrong
//  OTPViewController.swift //  FinalBookingApp // //  Created by Makwin Santhosh K on 19/10/22. // import UIKit import FirebaseAuth import Firebase import FirebaseCore class OTPViewController: UIViewController {          @IBOutlet weak var OTPLabel: UILabel!          @IBOutlet weak var EnterOTPLabel: UILabel!     @IBOutlet weak var MailTextField : UITextField!     @IBOutlet weak var PasswordTextField: UITextField!     @IBOutlet weak var EnterOTPTextField: UITextField!     @IBOutlet weak var VerifyButton: UIButton!     @IBOutlet weak var ErrorLabel : UILabel!               override func viewDidLoad() {         super.viewDidLoad()                  // Do any additional setup after loading the view.     }     // check the data validate Things     func validateFields() -> String?{         if PasswordTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" //   // im getting error in this error saying "Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"         {             return "Please enter the password without the BlankSpaces"         }         let cleanedPassword = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)         if Helpers.isPasswordValid(cleanedPassword) == false{             //Password wasn't secure enough             return "Please make sure your password is at least 8 characters, contains a special character and a number."         }         return nil     }          /*      // MARK: - Navigation            // In a storyboard-based application, you will often want to do a little preparation before navigation      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {      // Get the new view controller using segue.destination.      // Pass the selected object to the new view controller.      }      */          @IBAction func ButtonTapped(_ sender: Any) {         let error = validateFields()                  if error != nil {                          // There's something wrong with the fields, show error message             showError(error!)         }         else {             let Email = MailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)             let Password = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)             //MARK: Create a User             Auth.auth().createUser(withEmail: Email, password: Password){(result,err) in                 if err != nil {                                          // There was an error creating the user                     self.showError("Error creating user")                 }                 else {                                          let db = Firestore.firestore()                                                               db.collection("Users").addDocument(data: ["mail" : Email, "uid" : result!.user.uid])                 }             }             self.TransistiontoHome()         }              }                  func showError(_ message : String){             ErrorLabel.text = message             ErrorLabel.alpha = 1         }         func TransistiontoHome() {                      }          }
Replies
2
Boosts
0
Views
1.4k
Activity
Nov ’22
Transition from storyboard to Swift UI
this is not an code related doubt I have 2 two storyboard which is connected to each other say like LoginView and SignUpView in storyBoard and then I have create the HomeView in SwiftUI File How do I tell the Xcode to run the SwiftUI File after the LoginView.StoryBoard
Replies
2
Boosts
0
Views
2.3k
Activity
Nov ’22
how to add animation in Launch Screen
I have to added the background image and background colour in launch screen but for user experience i need to add the loading animation in launch screen, I also used the Activity indicator View but it is not moving (not showing animation) is there is any way to add LottieView or Rive Animation in Launch Screen
Replies
3
Boosts
0
Views
6.8k
Activity
Nov ’22
Publishing changes from within view updates is not allowed, this will cause undefined behavior.
Im building the small Map View by accessing the Users Location From the App Im getting this Error in Xcode 14 in Purple Color there is no error in this Code side it shows only while running in this simulator also according to the error My Location is not updating to it Can any 1 say where am I going wrong below is my code //  MapUIView.swift //  Login_Via_SwiftUI // //  Created by Makwin Santhosh K on 10/11/22. // import SwiftUI import MapKit import CoreLocationUI struct MapUIView: View {     @StateObject private var ViewModel = ContentViewModal()     var body: some View {         ZStack(alignment: .bottom) {             Map(coordinateRegion: $ViewModel.region, showsUserLocation: true)                 .ignoresSafeArea()                                       LocationButton(.currentLocation){                 ViewModel.requestUserLocationForOnce()             }             .foregroundColor(.white)             .cornerRadius(8)             .padding()                      }     } } struct MapUIView_Previews: PreviewProvider {     static var previews: some View {         MapUIView()                  } } final class ContentViewModal: NSObject, ObservableObject, CLLocationManagerDelegate{          @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 40, longitude: 120), span: MKCoordinateSpan(latitudeDelta: 100, longitudeDelta: 100))          let locationManager = CLLocationManager()          override init() {         super.init()         locationManager.delegate = self     }               func requestUserLocationForOnce() {         locationManager.requestLocation()     }          func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {         guard let latestLocation = locations.first else{             //show error             return         }         DispatchQueue.main.async {             self.region = MKCoordinateRegion(center: latestLocation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))         }     }     func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {         print(error.localizedDescription)     } }
Replies
4
Boosts
0
Views
3.2k
Activity
Nov ’22
Button to navigate through SwiftUI Views
this is my code I need my toolBar buttons to navigate to other SwiftUi views what should I write in button action { } to open the other SwiftUi View //  SwiftLoginView.swift //  Login FireBase // //  Created by Makwin Santhosh K on 08/11/22. // import SwiftUI import MapKit import CoreLocationUI struct OverallView: View {     var body: some View{                  NavigationView {             ZStack{                                  ToolBarShape()                     .frame(width: 400,height: 110)                     .foregroundColor(.white)                     .shadow(radius: 6)                     .offset(x : 0, y: 410)                                                     .toolbar {                         ToolbarItemGroup(placement: .bottomBar){                             //MARK: Button Home                             Button(action :{                                                              }, label:{                                 VStack {                                     Image(systemName: "house")                                     Text("Home")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Money                             Button(action :{                                                            },label:{                                 VStack {                                     Image(systemName: "dollarsign")                                     Text("Money")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Home                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "person")                                     Text("Help")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                             //MARK: Button Home                             Spacer()                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "menubar.rectangle")                                     Text("More")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                                                                                   }                                              }             }         }     } }      struct MapUView: View {     @StateObject public var ViewModel = ContentViewModal()          var body: some View {         ZStack(alignment: .bottom) {             AreaMap(region: $ViewModel.region)                          LocationButton(.currentLocation){                 ViewModel.requestUserLocationForOnce()             }             .foregroundColor(.white)             .cornerRadius(8)              }     }                                   struct AreaMap: View {         @Binding var region: MKCoordinateRegion                  var body: some View {             let binding = Binding(                 get: { self.region },                 set: { newValue in                     DispatchQueue.main.async {                         self.region = newValue                     }                 }             )             return Map(coordinateRegion: binding, showsUserLocation: true)                 .ignoresSafeArea()         }     }               final class ContenViewModal: NSObject, ObservableObject, CLLocationManagerDelegate{         @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 20, longitude: 90), span: MKCoordinateSpan(latitudeDelta: 100, longitudeDelta: 100))         let locationManager = CLLocationManager()                  override init() {             super.init()             locationManager.delegate = self         }                  func requestUserLocationForOnce() {             locationManager.requestLocation()         }                  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {             guard let latestLocation = locations.first else {                 //show error                 return             }             self.region = MKCoordinateRegion(center: latestLocation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))         }                  func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {             print(error.localizedDescription)         }     } } struct OverallView_Previews: PreviewProvider {     static var previews: some View {         OverallView()     } }
Replies
5
Boosts
0
Views
5.2k
Activity
Nov ’22