我想在我選擇的一天之前刪除所有日期,但不包括那一天,但我不能這樣做。由於從字典中刪除所有日期之前我選擇的日期
var dictionaryTotal: [String:String] = ["2017 01 01":"153.23", "2017 01 02":"162.45", "2017 01 04":"143.65", "2017 01 05":"140.78", "2017 01 06":"150.23"]
let date = NSDate()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
let TheStart = formatter.date(from: "2017 01 04")
for (key, value) in dictionaryTotal {
var ConvertDates = formatter.date(from: key)
}
使用Swift提供的結構來表示數據(在這種情況下,'Date'代替'NSDate'),除非有特定的原因需要使用其他版本。 – nathan