저는 신속한 언어에 익숙하지 않습니다. 해결할 수없는 문제가 있습니다. 전무신속한 클로저 내의 변수에 값 추가
그래서, 내 질문은 폐쇄 내부 변수에 어떻게 추가 값은 다음과 같습니다
내 응용 프로그램을 실행 한 후 나는 빈 문자열의 출력을 얻을?
때문에 나는 좌표의 출력을 얻을 수 있지만, 나중에 내 코드에서 내가 돈이 변수로 조작해야하기 때문에이 변수의 내부에 그 값을 필요 폐쇄 인쇄 (self.latLong) 내부에 라인을 추가 할 때
이 내 코드 '는 t는 폐쇄 내부의 모든 기능을 쓰고 싶은 :
import UIKit
import CoreLocation
import Firebase
var latLong: String!
override func viewDidLoad() {
super.viewDidLoad()
findCordiante(adress: "Cupertino, California, U.S.")
print(latLong)
}
func findCordiante(adress:String){
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(adress) {
placemarks, error in
if (placemarks != nil){
let placemark = placemarks?.first
let lat = placemark?.location?.coordinate.latitude
let lon = placemark?.location?.coordinate.longitude
self.latLong = String(describing: lat!) + "," + String(describing: lon!)
}else{
//handle no adress
self.latLong = ""
}
}
}
가능한 중복 https://stackoverflow.com/questions/39880506/swift-closure-async-order-of- 예를 들어, 자신의 완료 핸들러 패턴을 채용 실행) –