Hi I am using this code to try and animate a progress bar based on time.
import UIKit
class LoadingScreen: UIViewController {
@IBOutlet var progressView: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
var time = 0.0
var timer: NSTimer
timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector:Selector("setProgress"), userInfo: nil, repeats: true)
func setProgress() {
time += 0.1
progressView.progress = time / 3
if time >= 3 {
timer.invalidate()
}
}
However I get an error which says: cannot sign a value of type double to a value of type float.
EDIT:
The error is on this line:
progressView.progress = time / 3
Unless told otherwise swift compiler assumes type inference of Double for 0.0 - declare as
var time : Float = 0.0
Reference - https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html - Swift always chooses Double (rather than Float) when inferring the type of floating-point numbers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.