2016-10-18 88 views
5

我用Alamofire 4.0與雨燕3.0,但得到的問題與下面的代碼「沒有成員」錯誤與Alamofire 4.0斯威夫特3

類型爲「方法」(又名「OpaquePointer」)沒有成員'GET'

類型爲 '方法'(又名 'OpaquePointer')具有無構件 'PUT'

類型爲 '方法'(又名 'OpaquePointer')具有無構件 'POST'

類型「方法'(又名'OpaquePointer')沒有會員'PATCH'

類型爲 '方法'(又名 'OpaquePointer')沒有任何成員 '刪除'

枚舉定義:

enum Method { 
     case get 
     case put 
     case post 
     case patch 
     case delete 

     func toAFMethod() -> Alamofire.Method { 
      switch self { 
      case .get: 
       return Alamofire.Method.GET 
      case .put: 
       return Alamofire.Method.PUT 
      case .post: 
       return Alamofire.Method.POST 
      case .patch: 
       return Alamofire.Method.PATCH 
      case .delete: 
       return Alamofire.Method.DELETE 
      } 
     } 
    } 
+0

嘗試'Alamofire.HTTPMethod.get'等。 - HTTPMethod和小寫動詞https://github.com/Alamofire/Alamofire#http-methods。 – brandonscript

+0

...這些現在是'.get','.put'等等,小寫。 – Rob

回答

9

基於雨燕3 Alamofire 4.0存在API重大變化:

import Alamofire 

enum Method { 
    case get 
    case put 
    case post 
    case patch 
    case delete 

    func toAFMethod() -> Alamofire.HTTPMethod { 
     switch self { 
     case .get: 
      return Alamofire.HTTPMethod.get 
     case .put: 
      return Alamofire.HTTPMethod.put 
     case .post: 
      return Alamofire.HTTPMethod.post 
     case .patch: 
      return Alamofire.HTTPMethod.patch 
     case .delete: 
      return Alamofire.HTTPMethod.delete 
     } 
    } 
} 

Check Alamofire 4.0 Migration Guide For More Information.

希望這會對你有所幫助。