class AlamofireService {
static let alamofireService = AlamofireService()
private init() {
}
internal func makePostServiceRequest(url: String, parameters: AnyObject, completion: (inner:() throws -> NSDictionary) -> Void) -> Void{
Alamofire.request(.POST, URL_BASE, parameters: [IOS_PARAMS : parameters], encoding:.JSON).validate()
.responseJSON
{
response in switch response.result
{
case .Success(let JSON):
print("Success with JSON: \(JSON)")
let response = JSON as! NSDictionary
print(response)
completion(inner: { return response })
case .Failure(let error):
print("Request failed with error: \(error)")
completion(inner: { throw error })
}
}
}
internal func makeGetServiceRequestTemplates(completion: (inner:() throws -> NSDictionary) -> Void) ->Void {
Alamofire.request(.GET, URl_TEMPLATES).validate().responseJSON
{
response in switch response.result
{
case .Success(let JSON):
print("Success with JSON: \(JSON)")
if let array = JSON as? [Dictionary<String, AnyObject>] {
for var i=0; i < array.count; i++ {
let templates = Mapper<VQuizTemplateTo>().map(array[i])
print(templates)
}
}
completion(inner: { return response }) //error is on this line
case .Failure(let error):
print("Request failed with error: \(error)")
completion(inner: { throw error })
}
}
}
2つの同一メソッドがあります。最初はエラーがなく、2番目のメソッドはiとマークされています。何が間違っているのか分かりません。特にこの非センスのエラーです。 私は何が間違っているのか教えていただけますか?'応答<AnyObject、NSError>'の値を変換できません。結果タイプ 'NSDictionary'を閉じます。
何で
completion(inner: { return response })
を置き換える代わりにこれresponse.result.value as! NSDictionary
を返す試してみてください..あなたは、そのエラーを取得している理由である、タイプ
Response<AnyObject, NSError>
でありますあなたが得ているエラー? – renjithr