2016-08-28 8 views
1
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'を閉じます。

+0

何でcompletion(inner: { return response })を置き換える代わりにこれresponse.result.value as! NSDictionary

を返す試してみてください..あなたは、そのエラーを取得している理由である、タイプResponse<AnyObject, NSError>でありますあなたが得ているエラー? – renjithr

答えて

1

responseあなたが戻ってきているが

ちょうど

completion(inner: { return response.result.value as! NSDictionary })

+0

ありがとう、それは動作します!最初のAlamofireリクエストにエラーはありませんが、それでもそれを得ることはできませんが、これが重要です。 –

+0

リクエストにエラーはありませんが、タイプ 'Response を 'NSDictionary'に渡します。これが、あなたが受け取ったエラーの理由です。 – ebby94

関連する問題