Post

Replies

Boosts

Views

Activity

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
2.8k
Nov ’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.1k
Nov ’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
6.6k
Oct ’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
5.3k
Oct ’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
554
Sep ’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
1.7k
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
653
Aug ’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()
2
0
1.1k
Aug ’22