在这种情况下,下划线是什么意思? [英] What does the underscore mean in this case?
问题描述
迁移到Swift 2.0之前的代码:
my code before the migation to Swift 2.0:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "RhymeFavoriten") {
// pass data to next view
let dest = segue.destinationViewController as! FavoritenViewController
let source = segue.sourceViewController as! RhymeViewController // !!!!!!
dest.favoritenType = 1
dest.delegate = self
}
}
迁移告诉我将其更改为
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "RhymeFavoriten") {
// pass data to next view
let dest = segue.destinationViewController as! FavoritenViewController
_ = segue.sourceViewController as! RhymeViewController // !!!!!!!!!!
dest.favoritenType = 1
dest.delegate = self
}
或
func textSelected(selectedText:String, selectedType:Int) {
var fullTextArr = text.componentsSeparatedByString("\n")
var myArray = [String]() // !!!!!!
到
func textSelected(selectedText:String, selectedType:Int) {
var fullTextArr = text.componentsSeparatedByString("\n")
_ = [String]() // !!!!!!!!!
我看不到, _ = 代表什么:-(
I can´t see, what is _ = standing for :-(
推荐答案
_
是占位符.这意味着分配给_
的值将被忽略.
_
is a placeholder. It means that the values assigned to _
are ignored.
Xcode的迁移工具进行了此更改,因为它检测到您在任何地方都没有使用source
或myArray
,因此用占位符替换了这些变量.
Xcode's migration tool made this changes because it has detected that you didn't use source
or myArray
anywhere, thus replaced these variables by the placeholder.
现在,segue.sourceViewController as! RhymeViewController
的返回结果和[String]()
的返回结果没有被分配给变量.
Now instead of being assigned to a variable, the returning result of segue.sourceViewController as! RhymeViewController
and the returning result of [String]()
are ignored.
返回的结果将被忽略,但仍会在运行时对表达式进行求值:如果它具有副作用,则会发生这些影响.
The returning result is ignored but the expression is still evaluated at runtime: if it has side effects, these effects will occur.
因此,如果您实际上不需要这些说明,则应该完全删除它们.
So if you actually don't need these instructions you should get rid of them entirely.
这篇关于在这种情况下,下划线是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!