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 ...
随机推荐
- ES5新增数组方法(2):map
通过指定函数处理数组的每个元素,并返回处理后的数组. 1.计算数组中每个元素的平方 let arr = [1, 2, 3, 4, 5, 6]; let newArr = arr.map(item =& ...
- ES6 语法糖
重新认识ES6中的语法糖:https://segmentfault.com/a/1190000010159725
- final static 修饰(转载)
static修饰符 static修饰符能够与属性.方法和内部类一起使用,表示静态的.类中的静态变量和静态方法能够与类名一起使用,不需要创建一个类的对象来访问该类的静态成员,所以,stat ...
- Ubuntu 进阶命令——长期不定时更新
有时候远程连接服务器忽然中断或者不小心关掉了终端界面,正在运行的命令或者程序就会被强制停止.这时候,我们可以借助一些命令来避免这种情况的发生. nohup 不挂断地运行命令 & 在后台运行命令 ...
- Python 3 学习笔记之——键盘输入和读写文件
1. 键盘输入 Python提供了 input() 内置函数从标准输入读入一行文本,默认的标准输入是键盘.input 可以接收一个 Python 表达式作为输入,并将运算结果返回. str = inp ...
- 数据结构6——DFS
一.相关定义 深度优先遍历,也有称为深度优先搜索,简称DFS.其实,就像是一棵树的前序遍历. 初始条件:图G所有顶点均未被访问过,任选一点v. 思想:是从一个顶点V1开始,沿着一条路一直走到底,如果发 ...
- Introduction to TCP/IP
目录 First Week DHCP 子网掩码 ip路由表 Second Week ipv4 ipv6 TCP和UDP Third Week NAT RPC FTP E-mail Fouth Week ...
- jquery UI 跟随学习笔记——拖拽(Draggable)
引言 这周暂时没有任务下达,所以老大给我的任务就是熟悉jquery相关插件,我就先选择了jquery UI插件,以及jquery库学习. 我用了两天的时候熟悉Interactions模块中的Dragg ...
- PAT 1086 就不告诉你
https://pintia.cn/problem-sets/994805260223102976/problems/1038429065476579328 做作业的时候,邻座的小盆友问你:“五乘以七 ...
- qemu的drive参数解释
drive参数很简单,可以理解成是定义了一个实际的硬盘(或者是cd)与drive对应的是device-drive option[,option[,option[,...]]] Define a new ...


