I have the date being returned from the function today()
as an Int. But I want to assign this value to the variable theDate
as an integer. Here is my code:
The following is simply to get the date:
import UIKit
class ViewController: UIViewController {
let date = NSDate()
let formatter = DateFormatter()
let calendar = NSCalendar.current
Now I do stuff to this to isolate the date number. For some reason I have to do this in a function. So here that is:
func today() -> Int {
let x: Int = calendar.component(.day, from: date as Date)
return x
}
But now when I do let theDate = today()
it gives an error
How do I assign it to the variable theDate
?
If you don't know of a solution related to the method above, any other method that puts today's date as an integer in a variable is ok too because that's what I want. I am using Swift 3.