보기에서 간단한 디 버버를 만들려고하는데 .. 다음이 있습니다.
내가 가진 데이터를 수신, 요청을하는데 Alamofire를 사용하고 responseString
그것을 전송 다음과 App.log( response )
방향 debugViewController
의 log
당신이 예상하는에게 문자열을뿐만 아니라 볼 수있는 방법.
이제 이것을 컴파일하려고 시도하면 Swift를 처음 접했을 때 매우 이상한 오류가 반환됩니다. 문자열을 debugViewController.log()
실제로 예상되는 인수 유형으로 변환 할 수 없습니까 String
?
이것에 대해 가르쳐주세요.
여기 있습니다 debugViewController
:
import UIKit
class debugViewController: UIViewController {
@IBOutlet weak var debugTextField: UITextView!
@IBAction func dismissDebug(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
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 log( data: String ) {
debugTextField.text = data
}
}
여기에서 내가 전화를 걸고 데이터를 보내는 방법을 볼 수 있습니다.
Alamofire.request( .POST, API_URL, parameters: [ "action": "authenticate", "email": userEmail!, "password": userPassword! ] )
.responseString { response in
guard let value = response.result.value else
{
return App.alert( "error", message: "Did not receive data")
}
guard response.result.error == nil else
{
print( response.result.error )
return App.alert( "error", message: "An error occurred" )
}
App.log ( value )
}
debugViewController
클래스 (대문자로 클래스 이름을 시작하는 것이 좋습니다)이고 클래스 자체에서 인스턴스 메서드를 호출하려고 시도하므로 오류가 발생합니다 (실제로 유형의 인스턴스를 예상하기 때문입니다 debugViewController
).
debugViewController
클래스가 아닌 인스턴스에서 로그 메서드를 호출 할 수 있도록 생성 된 후에 의 인스턴스를 유지해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다