gpt4 book ai didi

ios - 从字典中获取日期值

转载 作者:行者123 更新时间:2023-11-29 05:57:05 25 4
gpt4 key购买 nike

我有一个这样声明的字典:

var result:[Workout] = []

结果中的值如下,使用print(result):

[Workout {
date = 2019-03-06 22:18:41 +0000;
name = Legday;
exercise = Bbb;
sets = 2;
reps = 1;
kg = 77;
notes = Bb;
}, Workout {
date = 2019-02-24 18:41:07 +0000;
name = bvcj;
exercise = Barbell Bench Press;
sets = 1;
reps = 1;
kg = 87;
notes = Kjj;
}, Workout {
date = 2019-02-22 08:02:23 +0000;
name = Chest;
exercise = Barbell Bench Press;
sets = 3;
reps = 6;
kg = 95;
notes = Ok med spot;
}, Workout {
date = 2019-02-22 08:02:23 +0000;
name = Chest;
exercise = Dips;
sets = 2;
reps = 6;
kg = 40;
notes = Lett, 1 ektra rep på siste sett;
}, Workout {
date = 2019-02-22 08:02:23 +0000;
name = Chest;
exercise = Incline Barbell Bench Press;
sets = 2;
reps = 6;
kg = 72.5;
notes = Tungt;
}, Workout {
date = 2019-02-22 08:02:23 +0000;
name = Chest;
exercise = Triceps Pushdown;
sets = 3;
reps = 12;
kg = 14.5;
notes = Ok;
}, Workout {
date = 2019-02-19 13:38:35 +0000;
name = Legday;
exercise = Squat;
sets = 2;
reps = 2;
kg = 77.5;
notes = Lett;
}, Workout {
date = 2019-02-19 13:38:35 +0000;
name = Legday;
exercise = Leg Press;
sets = 9;
reps = 8;
kg = 100;
notes = Tungt;
}, Workout {
date = 2019-02-18 10:54:34 +0000;
name = Legday;
exercise = Barbell Squat;
sets = 3;
reps = 6;
kg = 75;
notes = Tungt;
}, Workout {
date = 2019-02-18 10:54:34 +0000;
name = Legday;
exercise = Leg Extension;
sets = 10;
reps = 10;
kg = 32;
notes = Lett;
}, Workout {
date = 2019-02-17 21:48:52 +0000;
name = Legday;
exercise = Squat;
sets = 3;
reps = 6;
kg = 60;
notes = Lett;
}, Workout {
date = 2019-02-17 21:48:52 +0000;
name = Legday;
exercise = Tåhev;
sets = 4;
reps = 12;
kg = 40;
notes = Tungt;
}, Workout {
date = 2019-02-17 21:48:52 +0000;
name = Legday;
exercise = Leg Extension;
sets = 3;
reps = 6;
kg = 43.5;
notes = Lett;
}]

我只想获取每次锻炼的日期。我尝试了一些不同的方法,最接近的是使用这个:

var remoteIndexPath = NSIndexPath(row: 0, section: 0)
func didSelectDayView(_ dayView: DayView, animationDidFinish: Bool) {

let row = result[remoteIndexPath.row]

for i in result.indices { // Prøv dette i stedet for: for i in 0 ..< Results.count {
print(result[remoteIndexPath.row].date)
}
}

问题是它只打印第一个值 13 次:

Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)
Optional(2019-03-06 22:18:41 +0000)

有什么想法/提示吗?

最佳答案

你可以试试

let res = result.filter { compareDate(date1:$0.date, date2:savedDate) }
print(res)

关于ios - 从字典中获取日期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55053025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com