0

我正在尝试使用 HealthKit 读取数据,但在运行此代码时遇到一些问题:

do {
    let birthDay = try healthKitStore.dateOfBirth()
    let today = NSDate()
    let calendar = NSCalendar.currentCalendar()
    let differenceComponents = NSCalendar.currentCalendar().components(.YearCalendarUnit, fromDate: birthDay, toDate: today, options: NSCalendarOptions(0) )
    age = differenceComponents.year
} catch {
    print("Error reading Birthday: \(error)")
}

错误是

类型“NSCalendarUint”没有成员“YearCalendarUnit”

4

2 回答 2

2
let differenceComponents = NSCalendar.currentCalendar().components(NSCalendarUnit.Year, fromDate: birthDay, toDate: today, options: NSCalendarOptions(rawValue: 0))

NSCalendarUnit是一种结构类型。

于 2015-11-19T03:06:50.980 回答
0

⌥</kbd>-click on NSCalendar and scroll down. At the bottom of the page you'll see the NSCalendarUnit OptionSetType.

所有值都已更改为更方便的值,例如.Year, .Day,.Hour

于 2015-11-19T08:31:53.517 回答