I taught myself quickly, and I'm still very new, but I decided to create a simple program that prints the current time when you press the button. The code from the viewcontroller file is as follows:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var LblTime: UILabel!
@IBAction func BtnCalltime(sender: AnyObject) {
var time = NSDate()
var formatter = NSDateFormatter()
formatter.dateFormat = "dd-MM"
var formatteddate = formatter.stringFromDate(time)
LblTime.text = time
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
I have a problem with the line:
LblTime.text = time
I keep getting the error:
Cannot assign value of type "NSDate" to value of type "String?"
I tried using:
lblTime.text = time as! string?
and
lblTime.text = time as! string
but it still does not work, I would be very grateful for any help. Thanks
source
share