Passing property between two classes

Hi,


I've created a property which i can set:

import Foundation

class Settings {
    var _viewWards:String = ""

    var viewWards:String {
    get {
        if _viewWards == "" {_viewWards = "http://..."
    return _viewWards
    }
    set (newVal) {}
    }
}


In the first view controller i set the value based on user inputting the url:

var settings:Settings!
@IBAction func btnLoadWebServiceDataClick(_ sender: UIButton) {
        settings.viewWards = txtWSAddress.text!
    }


But when another button is clicked, the second view controler calls a service class, but has the init value, not the updated one:

var settings:Settings!
import Foundation
class WardService {
    var settings:Settings!
   
    init() {
        self.settings = Settings()
    }
   
    /
    func getWards(_ callback:@escaping ([String: Any]) ->()){
        request(settings.viewWards, callback: callback)
    }



Is this the correct way to go about this, or do i need a different approach. Appologies as im relatively new to iOS


If you need more clarification, please let me know


Thanks



Mark

In the init() of your WardService class, you are creating a new Settings object. You need to get a reference to the settings property of your first view controller instead. If you are using a segue, you will have a reference to the source and destination view controllers in the prepare(for segue: sender:) function. If you implement that function in your first view controller, you can either copy the settings from VC 1 to VC 2, or have a property on VC 2 that refers to VC 1 so you can check VC 1's settings directly from VC 2.

Passing property between two classes
 
 
Q