gpt4 book ai didi

ios - Swift CoreStore 订购列表监控问题

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

我有 NSManagedObject 数据模型 ExerciseEntity 我也有数据模式 MuscleEntity。我可以通过 exercise.muscle

访问肌肉对象

我添加了 CoreStore 监视器来观察数据模型的更改。

    typealias ListEntityType = ExerciseEntity
var monitor = CoreStore.monitorSectionedList(
From<ListEntityType>()
.sectionBy(#keyPath(ListEntityType.muscle.name)) { (sectionName) -> String? in
return "\(String(describing: sectionName)) years old"
}
.orderBy(.ascending(\.name))
)

我期望的结果是我的所有部分都是我的肌肉名称,并且每个部分都按顺序排列了练习,例如:

Abs section
1 exercise abs
2 exercise abs
Arms section
01 exercise arms
02 exercise arms

代替预期结果监视器为我返回交换结果,因为 01 和 02 字符串是 < 1 和 2 按升序练习ABS字符串:

Abs section
01 exercise arms
02 exercise arms
Arms section
1 exercise abs
2 exercise abs

我只是希望此升序排序规则在部分内部应用,而不是整个列表。

我已经打印了监视器:

    (lldb) po monitor
(CoreStore.ListMonitor<Stacked.ExerciseEntity>) (
.isPendingRefetch = false;
.numberOfObjects = 140;
.sections = 16 item(s) [
0 = "Abs" (
.numberOfObjects = 13;
.indexTitle = "Optional("Abs") years old";
);
1 = "Arms" (
.numberOfObjects = 1;
.indexTitle = "Optional("Arms") years old";
);

正如您所看到的,第 0 部分是腹肌,第 1 部分是 ARM ,好吧,让我们看一下物体:

        print("Section group name: ", monitor.sectionInfo(at: 0).name)
for e in monitor.objects(in: 0) {
print("Exercis name", e.name!, " Should connected to section named:", e.muscle!.name!)
}

print("Section group name: ", monitor.sectionInfo(at: 1).name)
for e in monitor.objects(in: 1) {
print("Exercis name", e.name!, " Should connected to section named:", e.muscle!.name!)
}

如果您不想阅读所有输出,您可以注意到第一个练习与 Arms 相关,但它以某种方式出现在 Abs 部分。

Section group name:  Abs
Exercis name 1111 Should connected to section named: Arms

完整输出:

Section group name:  Abs
Exercis name 1111 Should connected to section named: Arms
Exercis name Ab Crunch Machine Should connected to section named: Abs
Exercis name Abdominal Rollout Should connected to section named: Abs
Exercis name Air Bicycles Should connected to section named: Abs
Exercis name Alternating Dumbbell Curl Should connected to section named: Arms (Biceps)
Exercis name Arnold Dumbbell Press Should connected to section named: Shoulders (Anterior Deltoids)
Exercis name Barbell Bench Press Should connected to section named: Chest
Exercis name Barbell Curl Should connected to section named: Arms (Biceps)
Exercis name Barbell Deadlift Should connected to section named: Back
Exercis name Barbell Front Squat Should connected to section named: Legs (Quadriceps)
Exercis name Barbell Hip Thrust Should connected to section named: Glutes
Exercis name Barbell Holds Should connected to section named: Arms (Forearms)
Exercis name Barbell Lunge (In-Place) Should connected to section named: Legs (Quadriceps)
Section group name: Arms
Exercis name Barbell Lunge (Reverse) Should connected to section named: Legs (Quadriceps)

正如您所见,所有练习都按照以下规则排序:.orderBy(.ascending(\.name))

我想是通过部分订购的。

所以腹肌应该只包含腹肌练习,而 ARM 部分应该只包含 ARM 练习。

最佳答案

您正在告诉 ListMonitor .orderBy(.ascending(\.name)),所以这正是它按字母顺序执行的操作:

01 exercise arms
02 exercise arms
1 exercise abs
2 exercise abs

您将需要另一个属性来排序,该属性将尊重您的部分分组。

关于ios - Swift CoreStore 订购列表监控问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57515496/

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