Swift : missing argument label 'xxx' in call
http://stackoverflow.com/questions/24050844/swift-missing-argument-label-xxx-in-call
I need to use
Why ? If I put more than two var in func so that I need to write var name instead of first var when I call this func |
|||||||||||||||||
|
|
One possible reason is that it is actually a method. Methods are very sneaky, they look just like regular functions, but they don't act the same way, let's look at this:
Now here's the fun part, declare a function inside of a class and it's no longer a function ... it's a method
This is part of the design of behavior for methods Apple Docs:
Notice the autocomplete: |
|||||||||
|


|
This is simply an influence of the Objective-C language. When calling a method, the first parameter of a method does not need to be explicitly labelled (as in Objective-C it is effectively 'labelled' by the name of the method). However all following parameters DO need a name to identify them. They may also take an (optional) local name for use inside the method itself (see Jiaaro's link in the comments above). |
|||||
|
|
This is a quirk in the compiler. Functions (which are not members of a class) and class methods have different default behavior with regards to named parameters. This is consistent with the behavior of named parameters in objective-C (but makes no sense for someone new to swift with no experience with objective-C). Here's what the language reference has to say about named parameters for functions (specifically parameters where an external name for the parameter is not given, and the parameter does not have a default value)
For information about class methods, see Logan's answer. |
|||||||||
|
Swift : missing argument label 'xxx' in call的更多相关文章
- Swift 1.0: missing argument label 'xxx' in call
注意,这个问题是在swift1.0时发生的,swift2.0中,好像统一了function 和 method 的定义,具体待正式版发布后研究一下! 今天在使用swift时发现,写的func总是要求写出 ...
- linux报错 find: missing argument to `-exec'
在linux下使用find命令时,报错:find: missing argument to `-exec' 具体执行命令为: find /u03 -name server.xml -exec grep ...
- Loadrunner 运行场景时:missing newline in XXX.dat 错误解决
脚本参数化类型为file,在controller里运行场景的时候,报了个missing newline的错误,查了一下,将参数化的dat文件中的最后一行补上一个空行就解决啦!! 如果遇到此错误,需检查 ...
- swift学习之Label
//UILabel的使用方法 let label:UILabel = UILabel(frame: CGRect(x: 0, y: 100, width: view. ...
- Missing associated label more...
1.加上placeholder,可以为空 2.放在label标签中
- swift学习之label,button,imageView,字符串,数组,字典
import UIKit class ViewController: UIViewController,UITextFieldDelegate { var textField: UITextField ...
- find: missing argument to `-exec'
man find 发现 花括号要加 '' find ${LOG_BASE_DIR}$dir/ -type f -mtime +${KEEP_DAYS} -name ${LOG_REG} -exec r ...
- swift 动态获取label宽度或高度
func getLabHeigh(labelStr:String,font:UIFont,width:CGFloat) -> CGFloat { let statusLabelText: NSS ...
- Swift函数_默认参数
swift中提供了默认参数功能,在声明函数时给参数指定默认值. 例: func inputStudentInfo(name:String,age:Int="26") { print ...
随机推荐
- C++学习010-将某个地址转化为指针
如果需要将某个具体的地址转化为指针,可以直接使用类型那个转换来是实现. 实例如下 int main() { void* pData = (void*)(0x004001); std::cout < ...
- 名片管理系统demo
# 定义一个列表,用来储存名片 def cardInfors(): # 打印功能提示 print('欢迎使用名片管理系统v6.6.6') print('1:添加一个名片') print('2:删除一个 ...
- 第五篇Python基本数据类型
运算符 1. 结果是具体的值:算数运算符和赋值运算符 算数运算符:+.-.*./.**(幂).%(取余).//(取商) print(3-2) # 减法 print(3*2) # 乘法 print(3/ ...
- 3、shader深度测试(Cull、ZWrite 、ZTest )
剔除和深度测试是渲染法线中的一个流程 Cull:默认情况下,Unity中给的所有Shader都是单面的,它都把反面的渲染给关闭掉了,如果你在开发的过程中需要使用到双面,只要把cull关闭(off)即可 ...
- 最大流——EK算法
一.算法理论 [基本思想] 反复寻找源点s到汇点t之间的增广路径,若有,找出增广路径上每一段[容量-流量]的最小值delta,若无,则结束.在寻找增广路径时,可以用BFS来找,并且更新残留网络的值(涉 ...
- Java IO流-File类的使用示例-创建文件夹和文件的正确方法
当创建一个文件时,比如:E:\\test\\test.txt,此时若文件夹test不存在,那么直接创建文件会出错,故首先要判断文件夹是否存在,不存在的话要首先创建文件夹. public class F ...
- lintcode-135-数字组合
135-数字组合 给出一组候选数字(C)和目标数字(T),找到C中所有的组合,使找出的数字和为T.C中的数字可以无限制重复被选取. 例如,给出候选数组[2,3,6,7]和目标数字7,所求的解为: [7 ...
- java线程(2)——模拟生产者与消费者
前言: 我们都听说过生产者和消费者的例子吧,现在来模拟一下.生产者生产面包,消费者消费面包.假定生产者将生成出来的面包放入篮子中,消费者从篮子中取.这样,当篮子中没有面包时,消费者不能取.当篮子满了以 ...
- C++编码规范101
组织和策略问题 第0条 不要拘泥于小节(又名:了解哪些东西不应该标准化) 第1条 在高警告级别干净利落地进行编译 第2条 使用自动构建系统 第3条 使用版本控制系统 第4条 在代码审查上投入 设计风格 ...
- 用js通过url传参把数据从一个页面传到另一个页面
好长时间没写博客了,时值五一,外面到处人山人海,本宝宝还是好好呆在家学习吧.好了,言归正传.在没有后台支持的情况下,如何实现从一个页面像另一个页面来传递数据呢?应该很多人遇到过这个问题吧.那我就来说说 ...


