当我设置firstThing
为默认值时,nil
这将起作用,没有默认值nil
我得到一个错误,即调用函数时有一个缺少的参数.
通过键入Int?
我认为它使其成为可选的默认值nil
,我是对的吗?如果是这样的话,为什么没有它= nil
呢?
func test(firstThing: Int? = nil) {
if firstThing != nil {
print(firstThing!)
}
print("done")
}
test()
Run Code Online (Sandbox Code Playgroud) 以下扩展工作,但我想知道Swift是否有任何开箱即用的功能,这样做反向.我已经命令点击Bool,它没有任何反转,也没有在文档中看到任何内容.
var x = true
extension Bool{
mutating func reverse() -> Bool{
if self == true {
self = false
return self
} else {
self = true
return self
}
}
}
print(x.reverse()) // false
Run Code Online (Sandbox Code Playgroud) 我遇到了"拉动刷新"的问题.我使用的是UIViewController
同一个UITableView
里面,UIRefreshControl
目标设定为低于在这里:
public func refresh(sender: AnyObject) {
updateData()
refreshControl.endRefreshing()
}
override func viewDidLoad() {
super.viewDidLoad()
[...]
refreshControl.addTarget(self, action: Selector(("refresh:")), for: UIControlEvents.valueChanged)
}
Run Code Online (Sandbox Code Playgroud)
当我拉 - 有一个例外:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Income.MainVC refresh:]: unrecognized selector sent to instance 0x7faf1040a9e0
Run Code Online (Sandbox Code Playgroud)