swift - Swift编译器错误: The enum case has a single tuple as an associated value, but there are several patterns here

标签 swift

在Xcode 11.4 beta 3中构建一个项目,我在枚举中遇到了这个Swift Compiler错误:

The enum case has a single tuple as an associated value, but there are several patterns here, implicitly tupling the patterns and trying to match that instead



源代码:
switch result {
case .error(let err):
    //
case .value(let staff, let locations):  // <-- error on this line
    //
}
Result是一个通用枚举,具有.error.value的关联值。在这种情况下,关联的值为tupple。
public enum Result<T> {
    case value(T)
    case error(Error)
}

不要回想起以前曾遇到过此错误,并且搜索该错误不会产生任何结果。有任何想法吗?

最佳答案

我发现您也可以通过将相关值更像元组来处理(通过将其包装在一组额外的方括号中)来消除此错误:

switch result {
case .error(let err):
    //
case .value((let staff, let locations)):  
    //
}

关于swift - Swift编译器错误: The enum case has a single tuple as an associated value, but there are several patterns here,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60642312/

相关文章:

swift - 我怎么定义!!作为自定义后缀运算符?

ios - 在 UIImagePickerController 内的 UIBarButton 上添加系统摄像头

methods - 不允许部分应用协议(protocol)方法

xcode - 如何在 swift 2 命令行工具中创建最小守护进程?

ios - 我的 Sprites 在 Sprite Kit 中使用 Swift 被压缩

ios - 入职顺序的最佳模式(逻辑)是什么?

添加节标题后,Swift CollectionView 停止显示

swift - 解析与 swift 的集成

swift - 如何使用 Branch.io 将自定义图像添加到您的链接?

ios - 在 FScalendar swift 中禁用 future 日期选择