"has no member" error with Alamofire 4.0 with Swift 3

alamofire, ios, swift, swift3

Solution

Based on Swift 3 and Alamofire 4.0 there is major change in 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.

Hope this will help you.

Problem

I have used Alamofire 4.0 in with Swift 3.0 but getting issue with the following code Type 'Method' (aka 'OpaquePointer') has no member 'GET' Type 'Method' (aka 'OpaquePointer') has no member 'PUT' Type 'Method' (aka 'OpaquePointer') has no member 'POST' Type 'Method' (aka 'OpaquePointer') has no member 'PATCH' Type 'Method' (aka 'OpaquePointer') has no member 'DELETE' Enum definition: ``` 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 } } } ```

Original source