Cannot call non-functional calendar type value

I made a simple countdown application and I received this incorrect message: I can not call the value of the non-functional type "calendar".

What do i need to change?

    @IBOutlet weak var deteLabelOutlet: UILabel!
    let formatter = DateFormatter()
    let useCalendar = NSCalendar.current()
    let requesedComponent: NSCalendar.Unit = [
        NSCalendar.Unit.month,
        NSCalendar.Unit.day,
        NSCalendar.Unit.hour,
        NSCalendar.Unit.minute,
        NSCalendar.Unit.second
    ]

    override func viewDidLoad() {
        super.viewDidLoad()
        let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(printTime), userInfo: nil, repeats: true)
        timer.fire()
    }

    func printTime() {
        formatter.dateFormat = "MM/dd/yy hh:mm:ss a"
        let startTime = Date()
        let endTime = formatter.date(from: String("12/25/16 12:00:00 a"))

        let timeDiffrenece = useCalendar.components(requesedComponent,fromDate: startTime, toDate: endTime!, options: [] )

        deteLabelOutlet.text = "\(timeDiffrenece.month)Month \(timeDiffrenece.day) days \(timeDiffrenece.minute) minutes \(timeDiffrenece.second) seconds"
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
+4
source share
1 answer

In Swift 3, a calendar is currentnot a feature. Remove the parentheses.

In any case, it is strongly recommended to use your own design Calendar, as suggested in another answer

let useCalendar = Calendar.current

Edit:

, Swift 3 . , , .

deteLabelOutlet.text = "\(timeDiffrenece.month!)Month \(timeDiffrenece.day!) days \(timeDiffrenece.minute!) minutes \(timeDiffrenece.second!) seconds"
+1

Source: https://habr.com/ru/post/1680675/


All Articles