如何按自定义数组的日期对数组进行排序?

时间:2019-12-22 00:07:32

标签: arrays swift sorting

我有一个类似

的数组
var daysAvailableArray = [ScheduleModel]()

这是模型类

class ScheduleModel:NSObject{

var bookDate:String?

init(availableDay:String?) {

    //date calculation
    var day = Date.Weekday.monday
    switch availableDay {
    case "Monday":
        day = Date.Weekday.monday
    case "Tuesday":
        day = Date.Weekday.tuesday
    case "Wednesday":
        day = Date.Weekday.wednesday
    case "Thursday":
        day = Date.Weekday.thursday
    case "Friday":
        day = Date.Weekday.friday
    case "Saturday":
        day = Date.Weekday.saturday
    case "Sunday":
        day = Date.Weekday.sunday
    default:
        break
    }

    let formatter = DateFormatter()
    formatter.dateFormat = "MMMM dd"
    let nextDate = Date.today().next(day, considerToday: true)

    self.bookDate = availableDay! + ", " + formatter.string(from: nextDate)




}

}

我遇到的问题是bookDate返回为"Monday, December 23"。如何更改它以便可以将其分类为日期?

我还如何比较自定义对象的值,如答案here

0 个答案:

没有答案