我有一个对象数组,其中一个日期字段的类型为字符串。这是字段表示'UTC'日期字符串。我无法想办法在swift 3.0中的日期字段中对这个数组进行排序。
示例:
class Item {
var name: String
var type: String
var dateAdded: String //This contains UTC date string
init(name:String, type: String, dateAdded: String) {
self.name = name
self.type = type
self.dateAdded = dateAdded
}
}
var itemArray:[Item];
var item1 = Item(name: "Name1", type: "Person", dateAdded: "2018-03-05T13:15:30Z")
var item2 = Item(name: "Name2", type: "Animal", dateAdded: "2018-03-04T10:15:30Z")
itemArray.append(item1)
itemArray.append(item2)
感谢任何帮助。