gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:15:53 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com