简体   繁体   中英

“has no member” error with Alamofire 4.0 with Swift 3

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
            }
        }
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM