我正在尝试计算年龄
它正在向我显示此错误!
无法使用类型为(([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!)"
}
}