Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
避开Swift 3 Switch语句中的“从未使用过不可变值'variableName'的初始化”警告_Swift_Switch Statement - Fatal编程技术网

避开Swift 3 Switch语句中的“从未使用过不可变值'variableName'的初始化”警告

避开Swift 3 Switch语句中的“从未使用过不可变值'variableName'的初始化”警告,swift,switch-statement,Swift,Switch Statement,我有一些代码如下所示: fileprivate func enumSwitchTime(_ optionalString: String?) { if let nextEnumToSwitchOn = funcToGetEnum() switch nextEnumToSwitchOn { case .enumStateOne(let associatedEnumValue): if let optionalString = optionalString {

我有一些代码如下所示:

fileprivate func enumSwitchTime(_ optionalString: String?) {
    if let nextEnumToSwitchOn = funcToGetEnum()
    switch nextEnumToSwitchOn {
    case .enumStateOne(let associatedEnumValue):
        if let optionalString = optionalString {
            //do stuff with both associatedEnumValue and optionalString
        }
    case .enumStateTwo...
    .
    .
    .
    }
}
然而,由于Swift 3我使用的是Xcode 8.1,我得到的是不可变值“associatedEnumValue”的初始化从未使用过。。。关于第一个案例的警告

我的脚趾还在斯威夫特身上湿透,但到目前为止我看不出有什么办法。我不能在case语句中使用下划线参数,然后在let optionalString=optionalString之后声明关联的枚举值,或者至少我还没有找到任何方法


这只是一个警告,但我不喜欢代码中的警告。有没有办法解决这个问题?

嗯,事实证明这是一个Xcode错误/问题

在多次清理我的项目并重新启动Xcode之后,警告仍然存在,我在这里发布了这个问题,认为我遗漏了什么


在Martin R说如果在任何代码路径中使用了变量,警告就不应该出现之后,我仔细研究了代码,解开了那些更改,清理了项目,重新启动了Xcode,最后警告消失了。

为什么你会得到一个“associatedEnumValue”从未使用过警告,如果你使用associatedEnumValue做事情您可以发布一个编译自包含的示例吗?如果不需要关联的值,则只需匹配大小写即可。enumStateOne:。否则,除非我忽略了某些内容,否则您不应该得到警告。如果让nextEnumToSwitchOn=funcToGetEnum没有匹配的块,那么它甚至不会编译。请阅读,然后考虑更新您的问题。在编写这样一个MCVE的过程中,我怀疑您甚至可能会回答自己的问题,这是创建最小、完整和可验证示例的另一个很好的理由。Martin R,我确实需要关联的值,但我仅在确认optionalString参数不是nil后才使用它。因此,是的,警告是正确的:有一个代码路径不使用associatedEnumValue。我只是想知道是否有一个技巧,人们可以绕过这一点。我将看看今天晚些时候是否可以编译一些代码。如果在任何代码路径中使用该变量,则不应出现警告。是否有方法禁用此警告