在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/