Кто-нибудь знает, как я могу это решить? Я получаю эту ошибку:Swift: Невозможно преобразовать значение типа «NSDate» в ожидаемый тип аргумента «NSDateComponents»
¨cannot convert value of type 'NSDate' to expected argument type 'NSDateComponents'¨ on line:
произошла ошибка в строке:
let competitionDay = userCalendar.dateFromComponents(competitionDate)!
Это более полный фрагмент кода:
func Date() {
// Here we set the current date
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Hour, .Minute, .Second, .Nanosecond], fromDate: date)
let hour = components.hour
let minutes = components.minute
let month = components.month
let year = components.year
let day = components.day
let currentDate = calendar.dateFromComponents(components)
// here we set the due date. When the timer is supposed to finish
// final Calendar value
let userCalendar = NSCalendar.currentCalendar()
let competitionDate:NSDate = myDatePicker.date
competitionDate.timeIntervalSinceNow
let competitionDay = userCalendar.dateFromComponents(competitionDate)!
// Here we compare the two dates
competitionDay.timeIntervalSinceDate(currentDate!)
let dayCalendarUnit = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Hour, NSCalendarUnit.Minute], fromDate: date)
//here we change the seconds to hours,minutes and days
let competitionDayDifference = calendar.components([.Day, .Hour, .Minute],
fromDate: currentDate!, toDate: competitionDay, options: NSCalendarOptions())
//finally, here we set the variable to our remaining time
let daysLeft = competitionDayDifference.day
let hoursLeft = competitionDayDifference.hour
let minutesLeft = competitionDayDifference.minute
Какая линия отображает ошибку? –
Не ясно ли сообщение об ошибке? 'dateFromComponents()' принимает аргумент NSDateComponents. В 'dateFromComponents (contestDate)' вы передаете NSDate. –
@MartinR Знаете ли вы, как я могу это решить? Если вы можете показать его в коде, который был бы оценен – Gjeruldsen