title: Swift - Generate an Address Format from Reverse Geocoding
body: <p>I am trying to generate a Formatted Full address using CLGeocoder in Swift 3. I referred to this <a href="https://stackoverflow.com/a/32832601/4177142">SO</a> thread to get the code given below.</p>
  
  <p>However, sometimes the app crashes with a 'nil' error at the line:</p>
  
  <pre><code>//Address dictionary
  print(placeMark.addressDictionary ?? "")
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>How can I concatenate these values retrieved from the GeoCoder to form a full address? (Street + City + etc)</li>
  <li>How do I handle the nil error I get when the func is unable to find an address?</li>
  </ol>
  
  <p><strong>Full code:</strong></p>
  
  <pre><code>func getAddress() -&gt; String {
          var address: String = ""
  
          let geoCoder = CLGeocoder()
          let location = CLLocation(latitude: selectedLat, longitude: selectedLon)
          //selectedLat and selectedLon are double values set by the app in a previous process
  
          geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -&gt; Void in
  
              // Place details
              var placeMark: CLPlacemark!
              placeMark = placemarks?[0]
  
              // Address dictionary
              //print(placeMark.addressDictionary ?? "")
  
              // Location name
              if let locationName = placeMark.addressDictionary!["Name"] as? NSString {
                  //print(locationName)
              }
  
              // Street address
              if let street = placeMark.addressDictionary!["Thoroughfare"] as? NSString {
                  //print(street)
              }
  
              // City
              if let city = placeMark.addressDictionary!["City"] as? NSString {
                  //print(city)
              }
  
              // Zip code
              if let zip = placeMark.addressDictionary!["ZIP"] as? NSString {
                  //print(zip)
              }
  
              // Country
              if let country = placeMark.addressDictionary!["Country"] as? NSString {
                  //print(country)
              }
  
          })
  
          return address;
      } 
  </code></pre>