iOS Swift 3参数在前面有下划线 [英] iOS Swift 3 parameters have underscore in front

查看:166
本文介绍了iOS Swift 3参数在前面有下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我在Xcode中打开了我的项目,它需要将当前的Swift转换为Swift 3.转换后,我发现函数的所有参数都在前面有一个下划线。例如, func didGetWeather(_ weather:Weather){} 。我试图拿走下划线,它工作正常。我想知道那些下划线是什么。

解决方案

在swift3之前,默认情况下第一个参数的标签未在函数调用中列出,在swift3中,没有命名参数的方法是在签名中的参数名称之前放置下划线,swift3 migrator添加下划线函数第一个参数,以不破坏依赖于不在函数调用处放置第一个标签的现有代码。 / p>

Today I opened my project in Xcode and it required to convert current Swift to Swift 3. After the conversion, I found all parameters of functions have an underscore in front. For example, func didGetWeather(_ weather: Weather) {}. I tried to take away the underscores and it worked fine. I wonder what those underscores are for.

解决方案

Before swift3 the label of the first parameter by default was not listed in the function call, in swift3 does, the way to not name the parameters is placing an underscore before the parameter name in the signature, swift3 migrator add underscore the functions first parameter to not break existing code that rely on not placing the first label at function call.

这篇关于iOS Swift 3参数在前面有下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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