我正在收到'NSCalendar?'自XCode版本6.1(6A1052d)更新以来没有名为'components'的成员错误

时间:2014-11-28 13:42:41

标签: ios xcode cocoa-touch swift nspredicate

此更新为我打破了几件事。

以下是代码:

func convertStartAndExpiryDateFromPickerIntoString(datePicker: UIDatePicker) -> String {
    let dateFromPicker = datePicker.date
    let calendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)
    let unitFlags = NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit
    let components = calendar.components(unitFlags, fromDate: dateFromPicker)
    return "\(months.objectAtIndex(components.month)) \(components.day)"

}

有什么想法吗?

感谢您的时间

1 个答案:

答案 0 :(得分:0)

罗布建议工作时解开。

func convertStartAndExpiryDateFromPickerIntoString(datePicker: UIDatePicker) -> String {
        let dateFromPicker = datePicker.date
        let calendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
        let unitFlags = NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit
        let components = calendar.components(unitFlags, fromDate: dateFromPicker)
        return "\(months.objectAtIndex(components.month)) \(components.day)"

    }