Sorts skills specifically for the EditSkills view, but also more generally when creating a MonsterViewModel.
This commit is contained in:
@@ -138,7 +138,7 @@ class MonsterViewModel: ObservableObject {
|
||||
self.charismaScore = monster.charismaScore
|
||||
self.charismaSavingThrowAdvantage = monster.charismaSavingThrowAdvantageEnum
|
||||
self.charismaSavingThrowProficiency = monster.charismaSavingThrowProficiencyEnum
|
||||
self.skills = (monster.skills?.allObjects.map {SkillViewModel(($0 as! Skill))})!
|
||||
self.skills = (monster.skills?.allObjects.map {SkillViewModel(($0 as! Skill))})!.sorted()
|
||||
}
|
||||
|
||||
func copyToMonster(monster: Monster) {
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
class SkillViewModel: ObservableObject, Hashable, Identifiable {
|
||||
class SkillViewModel: ObservableObject, Comparable, Hashable, Identifiable {
|
||||
static func < (lhs: SkillViewModel, rhs: SkillViewModel) -> Bool {
|
||||
return lhs.name < rhs.name
|
||||
}
|
||||
|
||||
static func == (lhs: SkillViewModel, rhs: SkillViewModel) -> Bool {
|
||||
return lhs.abilityScore == rhs.abilityScore
|
||||
&& lhs.advantage == rhs.advantage
|
||||
|
||||
@@ -33,6 +33,9 @@ struct EditSkills: View {
|
||||
}
|
||||
)
|
||||
})
|
||||
.onAppear(perform: {
|
||||
monsterViewModel.skills = monsterViewModel.skills.sorted()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user