【发布时间】:2020-02-28 04:23:59
【问题描述】:
我正在尝试遍历从我的 API 收到的所有日期,并将它们转换为我的应用程序可用的格式。我在这段代码中遇到了错误
ForEach(dateList.indices, id: \.self) { date in
self.que = "";
for letter in dateList[date] {
if letter == "T" {
dateList[date] = self.que
return
}
else if letter == "-" {
self.que = self.que + "/"
}
else {
self.que = self.que + letter;
}
}
}
我正在尝试对 dateList 数组中的每个字符串进行迭代,并将其转换为可在我的应用程序中使用的格式。此格式将从 2020-02-28T03:32:44Z 变为 2020/02/28。我收到错误“对成员'索引'的模糊引用”,我不确定这意味着什么。
【问题讨论】:
-
您应该使用DateFormatter 从字符串中检索日期。
标签: ios arrays xcode foreach swiftui