Xcode:表达式的类型不明确,没有更多的上下文

时间:2015-08-31 15:33:42

标签: xcode swift ios9

Xcode错误:表达式的类型不明确,没有更多的上下文

我该如何解决?

let componentss = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: date)

2 个答案:

答案 0 :(得分:6)

在Swift 2.0中,

CalendarUnit名称已更改。试试这个:

let componentss = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: date)

答案 1 :(得分:0)

谢谢它有效!

dateFormat.dateStyle = NSDateFormatterStyle.ShortStyle
dateFormat.timeStyle = NSDateFormatterStyle.ShortStyle
datePicker.datePickerMode = UIDatePickerMode.DateAndTime
datePicker.addTarget(self, action: Selector("updateDateField:"),forControlEvents:UIControlEvents.ValueChanged)
yearLabel.inputView = datePicker

如何将其转换为 dd-MM-yyyy H:mm:ss