无法在Alamofire中使用公开枚举

时间:2015-10-12 07:19:52

标签: ios swift alamofire

我有这段代码:

import Alamofire

extension Alamofire.Request {
public func responseObject<T: ResponseJSONObjectSerializable>(completionHandler:(NSURLRequest?,NSHTTPURLResponse?, Result<T>) -> Void) -> Self {
let responseSerializer = GenericResponseSerializer<T> { request, response, data in

guard let responseData = data else {

    let failureReason = "Object could not be serialized because input data was nil."
    let error = Error.errorWithCode( .DataserializableFailed, failureReason: failureReason)
    //Error: Type of expression is ambiguous without more context

    return .Failure(data, error)

}}}

.DataserializableFailed在Alamofire中定义:

public struct Error {
public enum Code: Int {
    case InputStreamReadFailed           = -6000
    case OutputStreamWriteFailed         = -6001
    case ContentTypeValidationFailed     = -6002
    case StatusCodeValidationFailed      = -6003
    case DataSerializationFailed         = -6004
    case StringSerializationFailed       = -6005
    case JSONSerializationFailed         = -6006
    case PropertyListSerializationFailed = -6007
}
}

如果我在Code之前加.DataserializableFailed,它会说:使用未解析的标识符'代码'

怎么了?

1 个答案:

答案 0 :(得分:0)

显然你的大写/拼写是不同的。它应该是.DataSerializationFailed,而不是.DataserializableFailed

或者您可以参考Error.Code.DataSerializationFailed