我从:
开始var weekdays = ["Sunday", "Friday", "Tuesday"]
我需要将其更改为:
weekdays = ["Sunday", "Tuesday", "Friday"]
我已将它们转换为Ints:
var days = [Int]()
for day in weekdays {
let formatterWeekday = NSDateFormatter()
formatterWeekday.dateFormat = "e"
let weekday = formatterWeekday.dateFromString(day)
let weekdayString = formatterWeekday.stringFromDate(weekday!)
let dayInt = Int(weekdayString)
days.append(dayInt!)
}
days.sortInPlace()
然后给了我:
days = [1,3,6]
那么如何将Int
转换为工作日字符串?
答案 0 :(得分:4)
您是否考虑过简单方法?
更新了@Martin R
输入
let dateFormatter = NSDateFormatter()
// dateFormatter.weekdaySymbols = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for dayIndex in days
{
print(dateFormatter.weekdaySymbols[dayIndex])
}