Ваш Localized.string
файл должен быть
"Sunday" = "Воскресенье";
"Monday" = "Понедельник";
"Tuesday" = "Вторник";
"Wednesday" = "Среда";
"Thursday" = "Четверг";
"Friday" = "Пятница";
"Saturday" = "Суббота";
и
let day = NSLocalizedString(actualDate, comment: "")
cell.dayCollection.text = day
Обновление для отображения «Сегодня» как текущего дня
Сначала создайте Extension+Date.swift
файл. Добавьте приведенный ниже код в файл.
extension Date {
/// Compare self with another date.
///
/// - Parameter anotherDate: The another date to compare as Date.
/// - Returns: Returns true if is same day, otherwise false.
public func isSame(_ anotherDate: Date) -> Bool {
let calendar = Calendar.autoupdatingCurrent
let componentsSelf = calendar.dateComponents([.year, .month, .day], from: self)
let componentsAnotherDate = calendar.dateComponents([.year, .month, .day], from: anotherDate)
return componentsSelf.year == componentsAnotherDate.year && componentsSelf.month == componentsAnotherDate.month && componentsSelf.day == componentsAnotherDate.day
}
}
В вашем cellForRow
изменить на:
var actualDate = dateFormatter.string(from: date)
if date.isSame(Date()) {
actualDate = "Today"
}
Добавьте Today
ключ к вашему Localized.string
файлу
"Today" = "Cегодня";