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. |
|||||||||
|
最新文章
- ORACLE关闭启动的诡异错误
- bzoj1023: [SHOI2008]cactus仙人掌图
- BZOJ 2124: 等差子序列
- shared_ptr<;>; reset
- VSPM虚拟串口使用
- 配置SMarty解析
- Metadata Lock原理5
- oracle 字段上下两条记录的相减
- QT数据库使用案列【联系人】-- 使用sqlite和QStringListModel
- try、catch、finally与return
- C# 进销存系统开发框架
- 【LeetCode练习题】Unique Paths
- NSIS:判断程序是否运行并进行卸载
- [置顶] 实现360度全景图像的利器--PanoramaGL
- Mac关机时处于黑屏状态
- Session 和 Cookie 区别
- WEB实现单元格合并
- Centos7下mysql5.7.22主从配置
- TCP/UDP区别&;&;心跳包机制【转】
- eclipse从svn导入maven项目变成普通项目解决办法
热门文章
- 每天一个Linux命令(12):su命令
- idea在Maven Projects中显示灰色的解决办法
- JMeter学习笔记(九) 参数化4--User Variables
- [Mac]Mac OS X中WireShark的使用,及找不到网卡问题的解决方法
- capacilitys 持续集成
- c# 调用 matlab 引发初始化错误 异常
- hadoop datanode 和 tasktracker起不来
- [洛谷P2763]试题库问题
- 解析Mybaits的insert方法返回数字-2147482646的原因
- 用JavaScript写一个类似PHP print_r的函数