如何修复无法调用类型为'([[Calendar.Component],from:Date,to:Data)'的参数列表的'dateComponents'

时间:2019-06-19 01:18:05

标签: swift calendar uidatepicker

我正在尝试计算年龄

它正在向我显示此错误!

  

无法使用类型为(([Calendar.Component],从:日期,到:数据)”的参数列表调用'dateComponents'

我的代码:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var dataPicker: UIDatePicker!
    @IBOutlet weak var laShowAge: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    @IBAction func buGetMyAge(_ sender: Any) {
        let certtenTime = Data()
        let userDB = dataPicker.date
        let calender = Calendar.current
        let component = calender.dateComponents( [Calendar.Component.day], from: userDB, to: certtenTime) // Cannot invoke 'dateComponents' with an argument list of type '([Calendar.Component], from: Date, to: Data)'*emphasized text*

        laShowAge.text = "Age in days= \(component.day!)"
    }

}

0 个答案:

没有答案