我一直在这里寻找很多问题,我发现一个类似标题的枚举案例开关没有在类型中找到,但对我来说没有解决方案.
我想使用带有自身变异的枚举来解决问题,在个别状态下,下一个交通灯颜色是什么.
enum TrafficLights {
mutating func next() {
switch self {
case .red:
self = .green
case .orange:
self = .red
case .green:
self = .orange
case .none:
self = .orange
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已将所有案例作为可能的选项,它仍然返回错误:
在'TrafficLights'类型中找不到枚举"案例"
我很好奇这些语法语句中哪一个(更)正确.游乐场愉快地编写了两个案例.
方法1
// copied from SO and this appears clear to me
UIView.animate(
withDuration: 3.0,
animations: {
},
completion: { (Bool) in
// completion code
}
)
Run Code Online (Sandbox Code Playgroud)
方法2
UIView.animate(
withDuration: 3.0,
animations: {
// code
}) {(Bool) in
// code when finished?
// argument label completion missing?
}
Run Code Online (Sandbox Code Playgroud)
为什么第二种方法中的圆括号在最后一个参数之前被关闭?或者是另一种实现UIView.animation
?