【问题标题】:Xcode: Type of expression is ambiguous without more contextXcode:表达式类型不明确,没有更多上下文
【发布时间】:2015-08-31 15:33:41
【问题描述】:

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

我该如何解决?

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

【问题讨论】:

    标签: xcode swift ios9


    【解决方案1】:

    CalendarUnit 名称在 Swift 2.0 中已更改。试试这个:

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

    【讨论】:

    • 好吧,它可以工作,但这一次,还有另一个错误:let cal = NSCalendar.currentCalendar() let sec = cal.components(.CalendarUnitSecond, fromDate: startDate, toDate: endDate, options: [ ])
    • 没有更多的.CalendarUnitSecond。将其更改为 [.Second]
    【解决方案2】:

    谢谢它有效!

    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

    【讨论】:

      猜你喜欢
      • 2020-03-05
      • 2019-11-03
      • 1970-01-01
      • 2021-05-17
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 1970-01-01
      相关资源
      最近更新 更多