在这种情况下,下划线是什么意思? [英] What does the underscore mean in this case?

查看:210
本文介绍了在这种情况下,下划线是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迁移到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的迁移工具进行了此更改,因为它检测到您在任何地方都没有使用sourcemyArray,因此用占位符替换了这些变量.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆