斯威夫特(Swift):“ _,_”是什么意思?手段? [英] Swift : What does "_, _ " means?

查看:119
本文介绍了斯威夫特(Swift):“ _,_”是什么意思?手段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对Alamofire进行一些研究,发现了以下代码块:

I was doing some research on Alamofire and I came across this block of code:

    switch encodingResult {

    case .Success(let upload, _, _):

    upload.responseJSON { response in

        if let info = response.result.value as? Dictionary<String, AnyObject> {

            if let links = info["links"] as? Dictionary<String, AnyObject> {

                if let imgLink = links["image_link"] as? String {

                    print("LINK: \(imgLink)")
                }
            }
        }

    } case .Failure(let error):
        print(error)
}

我可以知道什么吗_,_是什么意思?

May I know what does _, _ means?

我见过它的用法,例如 let _ = xyz ,但是我有

I have seen uses of it like let _ = "xyz" but i have never seen it used like the code above before.

这是否意味着它有2个未使用的参数?

Does it mean that it has 2 parameters that are not being used?

预先感谢

推荐答案

是的,这基本上意味着它们是未使用的值,在 Apples文档

Yes it basically means that they are unused values, it is describe here in Apples documentation.


通配符模式

Wildcard Pattern

通配符模式匹配并忽略任何值,并包含
下划线(_)。当您不关心要匹配的
值时,请使用通配符模式。例如,下面的代码在闭合范围1 ... 3中迭代
,而在每次循环迭代时忽略
范围的当前值:

A wildcard pattern matches and ignores any value and consists of an underscore (_). Use a wildcard pattern when you don’t care about the values being matched against. For example, the following code iterates through the closed range 1...3, ignoring the current value of the range on each iteration of the loop:

for _ in 1...3 {
  // Do something three times.
}


这篇关于斯威夫特(Swift):“ _,_”是什么意思?手段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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