Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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
            }
        }
    }
like image 625
Lovelini Rawat Avatar asked Oct 18 '16 04:10

Lovelini Rawat


1 Answers

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.

like image 174
Ashish Kakkad Avatar answered Oct 17 '22 00:10

Ashish Kakkad