2016-05-05 89 views
2

我試圖執行GET請求,但我得到以下兩個錯誤:斯威夫特2:Alamofire GET發行

使用未解決的標識符 '自我'

預期申報

這是我受影響的代碼

let credentialData = "\(self._username):\(self._password)".dataUsingEncoding(NSUTF8StringEncoding)! 
let base64Credentials = credentialData.base64EncodedStringWithOptions([]) 
let headers = ["Authorization": "Basic \(base64Credentials)"] 
Alamofire.request(.GET, "http://gemcave.pythonanywhere.com/api/order\(self._username)/\(self._password)", headers: headers) 
.responseJSON { response in 
debugPrint(response) 
} 

Errors encountered

回答

1

你需要把你的代碼是這樣一些方法:

func networkConfiguration() { 
    let credentialData = "\(self._username):\(self._password)".dataUsingEncoding(NSUTF8StringEncoding)! 
    let base64Credentials = credentialData.base64EncodedStringWithOptions([]) 
    let headers = ["Authorization": "Basic \(base64Credentials)"] 
    Alamofire.request(.GET, "http://gemcave.pythonanywhere.com/api/order\(self._username)/\(self._password)", headers: headers) 
    .responseJSON { response in 
    debugPrint(response) 
    } 
}