我有这个代码:
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
之前,它将说:使用未解析的标识符“代码”怎么了?
最佳答案
显然,您的大小写/拼写是不同的。应该是.DataSerializationFailed
,而不是.DataserializableFailed
。
或者,您可以参考Error.Code.DataSerializationFailed
。
关于ios - 无法在Alamofire中使用公共(public)枚举,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33075332/