Q:

Getting location using another class not working when calling function swift

I was using the ViewController class before to get the users updates but now when expanding the application i needed to move it to another class that simply handles all the location updates. Here is the code that i am using now:
class ViewController: UIViewController, UITextFieldDelegate {

    @IBAction func pickMeUpButton(sender: AnyObject) {

        sendPushNotificationController().sendPushNotification("sendRequest",userLat: defaults.stringForKey("userLat")!, userLong: defaults.stringForKey("userLong")! )
    }

    @IBOutlet var numberForPickup: UITextField!

    let defaults = NSUserDefaults.standardUserDefaults()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.numberForPickup.delegate = self

        getLocationController().initLocation()
    }

So i made another class called getLocationController with an init function that should start the location updates. Here is the code:
class getLocationController: UIViewController, CLLocationManagerDelegate {

var locationManager: CLLocationManager!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func initLocation(){

    print("Im in here")

    locationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()
    locationManager.startUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {

    print("In location")

    if UIApplication.sharedApplication().applicationState == .Active {

        print("App in Foreground")

    }else {

        let Device = UIDevice.currentDevice()
        let iosVersion = Double(Device.systemVersion) ?? 0

        let iOS9 = iosVersion >= 9
        if iOS9{
            locationManager.allowsBackgroundLocationUpdates = true;
            locationManager.pausesLocationUpdatesAutomatically = false;
        }
        //let iOS7 = iosVersion >= 7 && iosVersion < 8
        print("App is backgrounded. New location is %@", newLocation)
    }
}
}

Now the print in initLocation is printed but not the print in didUpdateLocations. I used the very same code in ViewController class and it worked perfectly fine. Now when i am trying to move it to another class that is now really a view on the phone but simply a helper class its not working. Any ideas why?

A:

I don't see you assigning the getLocationController to a variable anywhere in the ViewController. That means the getLocationController would go out of scope and be destroyed, wouldn't it? That would explain why the callback didUpdateToLocation  isn't called. 
Try:
class ViewController: UITextFieldDelegate {

@IBAction func pickMeUpButton(sender: AnyObject) {

    sendPushNotificationController().sendPushNotification("sendRequest",userLat: defaults.stringForKey("userLat")!, userLong: defaults.stringForKey("userLong")! )
}

@IBOutlet var numberForPickup: UITextField!

let defaults = NSUserDefaults.standardUserDefaults()

var glc:getLocationController // is this how it is in Swift?!

override func viewDidLoad() {
    super.viewDidLoad()

    self.numberForPickup.delegate = self

    glc = getLocationController()
    glc.initLocation()
}

