【问题标题】:"has no member" error with Alamofire 4.0 with Swift 3使用 Swift 3 的 Alamofire 4.0 出现“没有成员”错误
【发布时间】:2016-10-18 04:23:30
【问题描述】:

我在 Swift 3.0 中使用过 Alamofire 4.0,但遇到以下代码问题

类型“方法”(又名“OpaquePointer”)没有成员“GET”

类型“方法”(又名“OpaquePointer”)没有成员“PUT”

类型“方法”(又名“OpaquePointer”)没有成员“POST”

类型“方法”(又名“OpaquePointer”)没有成员“补丁”

类型“方法”(又名“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
            }
        }
    }

【问题讨论】:

标签: ios swift swift3 alamofire


【解决方案1】:

基于 Swift 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.

希望这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多