I have a View Controller which has a UITextField and a button below it which i want to configure it when its pressed to save the data which are in the UITextField and store that data to the API class, Ill show some of the code and images below
So the default must be the URL that you are seeing but If the user decide to change that and press the button "Ruaj" then the URL needs to be updated in the APICaller class to, Ill show how the code is structured in the APICaller class where the URL needs to be updated
The code for the Settings class:
@IBOutlet weak var apiTextField: UITextField!
@IBOutlet weak var saveButton: UIButton!
@IBAction func theSaveButton(_ sender: Any) {
let alert = UIAlertController(title: "", message: "The configurations are being saved...", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
Timer.scheduledTimer(withTimeInterval: 3, repeats: false) { _ in
guard let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "qrCode") else {
return
}
tabBarController.modalPresentationStyle = .custom
self.present(tabBarController, animated: true, completion: nil)
}
}
The APICaller class:
class APICaller {
let token = "NjQzODM2N0NDNDM4GSH350NjA03536GSE3E="
static let shared = APICaller()
var baseURL = "http://411.42.111.234:3050/api/" // the URL when save Button is pressed needs to update the baseURL here :)
func getVehicles(for id: String, completed: @escaping (Result<[Vehicles],OnTraErrors>) -> Void ){
let endpoint = baseURL + "GetVehicles/?UserIdentificationValue=\(id)"
I believe this might be very easy but for me as a new Swift wanabe Dev I am having difficulties like everyone who started out this journey but I am truly learning on daily basis through this amazing community!