일부 게시물을 읽었으며 비슷한 게시물 (Swift closure with Alamofire)에 권장 사항이 있으며 내 코드와 동일한 작업을 시도했지만 지금 함수를 호출 할 방법을 찾을 수 없습니까? 표현의 형식을 변환 할 수 없습니다 '(응답 : @lvalue 문자열)'를 입력하기 :스위프트 함수 완성
import UIKit
class myClass101: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
var api_error: String = ""
activityInd.startAnimating()
call_api_function(response: api_error)
activityInd.stopAnimating()
if (api_error != "") {
let alertController = UIAlertController(title: "Server Alert", message: "Could not connect to API!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
}
}
'>() ((응답 - ->() 문자열))'
가 나는 오류를 얻을 수 기능은 다음과 같습니다 :
func call_api_function(completion: (response: String) ->()) {
let api_url_path: String = "http://\(str_api_server_ip):\(str_api_server_port)"
let api_url = NSURL(string: api_url_path + "/devices.xml")!
Alamofire.request(.GET, api_url)
.authenticate(user: str_api_username, password: str_api_password)
.validate(statusCode: 200..<300)
.response { (request, response, data, error) in
var senderror: String = error!.localizedDescription
completion(response: senderror)
if (error != nil) {
println(senderror)
}
// do other tasks here
}
}
고마워요!
코스타스
많은 의견을 보내 주셔서 감사합니다. 매우 감사!!!! – Kostas
그건 그렇고, [귀하의 다른 질문에 대한 답변] (http://stackoverflow.com/a/27089820/1271826) 두 매개 변수와 폐쇄의 예를 보여줍니다. 분명히 XML을 다루므로 파싱을 원할 수도 있지만 다른 대답은 클로저를 통해 두 개의 매개 변수를 전달하는 아이디어를 보여줍니다. – Rob