简体   繁体   English

如何从该结构访问成功/失败案例?

[英]How can I access Success/Failure cases from this struct?

在此处输入图片说明

Using Alamofire v4.0, Alamofire.upload() using MultipartFormData has changed, but I can't find out how to get the success/error case with the enumeration returned in the closure (type is SessionManager.MultipartFormDataEncodingResult ) 使用Alamofire v4.0,使用MultipartFormData Alamofire.upload()发生了变化,但是我无法找到如何在闭包中返回枚举的情况下获得成功/错误的情况(类型为SessionManager.MultipartFormDataEncodingResult

Looking into the SessionManager.MultipartFormDataEncodingResult struct, here is what I get: 查看SessionManager.MultipartFormDataEncodingResult结构,这是我得到的:

public enum MultipartFormDataEncodingResult {
    case success(request: UploadRequest, streamingFromDisk: Bool, streamFileURL: URL?)
    case failure(Error)
}

So Xcode seems to have been super unhelpful here and autocompleted the initialiser for that enum rather than the case statement. 因此,Xcode在这里似乎无济于事,并自动完成了该枚举的初始化程序,而不是case语句。 You would want to do something similar to what you have for the .failure case: 您可能想要执行与.failure情况类似的.failure

switch encodingResult {
case .success(let request, let streamingFromDisk, let streamFileURL):
    // you can now access request, streamingFromDisk and streamFileURL in this scope
    ...
case .failure(let errorType):
    // you can now access errorType in this scope
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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