最近我看到了Apple的2015年WWDC主题演讲.我也查看了一些文档,但是我找不到"if if pattern"部分,它是如何写在他们展示的幻灯片上的.(来自Apple Events的 68分00秒视频)
你知道这是指什么吗?还是语法?
对于简单的情况,if let或者guard我没有看到优势,
if case let x? = someOptional where ... {
...
}
//I don't see the advantage over the original if let
if let x = someOptional where ... {
...
}
Run Code Online (Sandbox Code Playgroud)
对于for-case-let简化使用可选集合的情况,我真的希望swift可以更进一步:
for case let x? in optionalArray {
...
}
//Wouldn't it be better if we could just write
for let x? in optionalArray {
...
}
Run Code Online (Sandbox Code Playgroud)
谷歌一段时间之后我认为唯一有用的案例是" Swift 2模式匹配:解开多个选项 ":
switch (username, password) {
case let (username?, password?):
print("Success!")
case …Run Code Online (Sandbox Code Playgroud)