快速使用逗号 [英] Comma usage in swift
问题描述
@IBAction函数func selectedGame(segue:UIStoryboardSegue){
如果让gamePickerViewController = segue.sourceViewController为? GamePickerViewController,
selectedGame = gamePickerViewController.selectedGame {
detailLabel.text = selectedGame
game = selectedGame
}
}
大家好,我正在按照一个教程来学习有关swift的知识。昨天我找到了代码的这一部分,但是我找不到找到理解逗号含义的方法。您能解释一下吗?
逗号用于将多个可选绑定组合到一个语句中,以避免不必要的嵌套。
p>从Swift 1.2开始,if let构造现在可以立即打开多个可选对象,并包括中间的布尔条件。这样一来,您就可以表达条件控制流而不必进行不必要的嵌套。更多详细信息
例如:
var foo:Int!
var bar:字符串!
// Swift 1.2
if let foo = foo,bar = bar {
// foo&酒吧有价值观。
} else {
}
//在Swift 1.2之前
如果让foo = foo {
//嵌套如果让bar = bar {
// foo&酒吧有价值。
}
}
Xcode6.3及更高版本支持Swift1.2。 / p>
@IBAction func selectedGame(segue:UIStoryboardSegue) {
if let gamePickerViewController = segue.sourceViewController as? GamePickerViewController,
selectedGame = gamePickerViewController.selectedGame {
detailLabel.text = selectedGame
game = selectedGame
}
}
Hi all, i'm following a tutorial to learn something about swift. Yesterday I found this part of code but I can not find a way to understand what it means thatcomma means. Can u pls explain me?
The comma is used to combine multiple optional bindings into one statement to avoid unnecessary nesting.
From Swift 1.2,The if let construct can now unwrap multiple optionals at once, as well as include intervening boolean conditions. This lets you express conditional control flow without unnecessary nesting.More details
For example:
var foo: Int!
var bar: String!
// Swift 1.2
if let foo = foo,bar = bar {
// foo & bar have values.
} else {
}
// before Swift 1.2
if let foo = foo {
// nesting
if let bar = bar {
// foo & bar have value.
}
}
Xcode6.3 and above support Swift1.2.
这篇关于快速使用逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!