title: Get location results from another class in swift
body: <p>How to get location results from one class (GPSLocation) from (userLocation.swift) and use them in another class in file (target.swift)..?</p>
  
  <p>I need countryCode, city, longitude and latitude from:</p>
  
  <p><strong>userLocation.swift</strong></p>
  
  <pre><code>import UIKit
  import MapKit
  
  class GPSLocation {
  
  func getGPSLocation(completion: () -&gt; Void) {
  
      let locManager = CLLocationManager()
      var currentLocation: CLLocation!
      locManager.desiredAccuracy = kCLLocationAccuracyBest
  
      if (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways) {
  
          currentLocation = locManager.location
  
          let latitude = String(format: "%.7f", currentLocation.coordinate.latitude)
          let longitude = String(format: "%.7f", currentLocation.coordinate.longitude)
          let location = CLLocation(latitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)
  
          fetchCountryAndCity(location: location) { countryCode, city in
              // debugPrint("Country:", countryCode)
              // debugPrint("City:", city)
          }
          // debugPrint("Latitude:", latitude)
          // debugPrint("Longitude:", longitude)
      }
  }
  
  //MARK: Find countryCode &amp; City name from longitude &amp; latitude
  
  func fetchCountryAndCity(location: CLLocation, completion: @escaping (String, String) -&gt; ()) {
      CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
          if let error = error {
              debugPrint(error)
          } else if let countryCode = placemarks?.first?.isoCountryCode,
              let city = placemarks?.first?.locality {
              completion(countryCode, city)
          }
      }
  }
  }
  </code></pre>
  
  <p>And print them in file:</p>
  
  <p><strong>target.swift</strong></p>
  
  <pre><code>import Foundation
  
  class Post {
  
   fileprivate func Post() {
  
      func getLocation() {
          // Get user GPS location (longitude, latitude, Country Code, City)
          let getUserLocation = GPSLocation()
          getUserLocation.getGPSLocation {
              debugPrint("Country:", countryCode)
              debugPrint("City:", city)
              debugPrint("Latitude:", latitude)
              debugPrint("Longitude:", longitude)
          }
      }
  
    }
  
  }
  </code></pre>
  
  <p>Thank you in advance..!!!</p>