这是我在Swift编程中的第一天,到现在为止我们正在使用Objective C.我试着编写简单的附加程序.喜欢,
var i = 10
var j = 10
var k = i + j
println(k)
Run Code Online (Sandbox Code Playgroud)
但是当我将其中一个值更改为float时,它会给出错误.
var i = 10
var j = 10.4
var k = i + j
println(k)
Run Code Online (Sandbox Code Playgroud)
错误:main.swift:13:11:无法找到接受提供的参数的'+'的重载
现在我做谷歌搜索,并尝试了一些事情Double(i+j),但它不起作用.在这种情况下,Swift应该隐式地将int转换为float,不是吗?
请告知我是否在理解Swift语言时遇到任何错误.
如何在Xcode中添加延迟?
self.label1.alpha = 1.0
//delay
self.label1.alpha = 0.0
Run Code Online (Sandbox Code Playgroud)
我想让它等待大约2秒钟.我读过有关time_dispatch和导入darwin库的内容,但我无法使其工作.那么有人可以一步一步地解释它吗?
首先我使用 arc4random 创建了一个 randomDelay 值
然后我想将 randomDelay 值添加到 DispatchQueue 以创建一个随机时间延迟变量
这是我的代码:
func animation1() {
UIView.animate(withDuration: 1, animations: {
// various code
}, completion: { (true) in
//delay calling the function by the randomDelay value of '0' to '2' seconds
let randomDelay = arc4random_uniform(3)
DispatchQueue.main.asyncAfter(deadline: .now() + randomDelay) { // the randomDelay value throws an unresolved identifier 'randomDelay' error
self.showAnimation2() // Go to the next function
}
})
}
Run Code Online (Sandbox Code Playgroud)
谢谢