Skip to content

Commit 4585ee3

Browse files
committed
Updates to conform to idiomatic Swift.
1 parent 0c52b2f commit 4585ee3

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

Examples/CharacterGenerator/CharacterGenerator/CharacterGenerator/Player/PlayerDetailView.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ struct PlayerDetailView: View {
2424
ForEach(0..<characterSheet.numberOfSections, id: \.self) { section in
2525
HStack(spacing: 6) {
2626
ForEach(0..<characterSheet.numberOfItems(in: section), id: \.self) { item in
27-
let indexPath = IndexPath(item: item, section: section)
28-
traitView(for: indexPath)
27+
traitView(for: section, item: item)
2928
}
3029
}
3130
.padding()
32-
.background(Color(.secondarySystemBackground))
31+
.background(.background.secondary)
3332
.cornerRadius(12)
3433
}
3534
}
@@ -40,10 +39,10 @@ struct PlayerDetailView: View {
4039
}
4140

4241
@ViewBuilder
43-
private func traitView(for indexPath: IndexPath) -> some View {
44-
let cellIdentifier = characterSheet.cellIdentifiers[indexPath.section][indexPath.item]
45-
let keys = characterSheet.keys[indexPath.section][indexPath.item]
46-
let label = characterSheet.labelKeys[indexPath.section][indexPath.item]
42+
private func traitView(for section: Int, item: Int) -> some View {
43+
let cellIdentifier = characterSheet.cellIdentifiers[section][item]
44+
let keys = characterSheet.keys[section][item]
45+
let label = characterSheet.labelKeys[section][item]
4746

4847
switch cellIdentifier {
4948
case "labeledText":
@@ -198,7 +197,7 @@ struct AbilityItemView: View {
198197
}
199198
.padding(8)
200199
.frame(maxWidth: .infinity)
201-
.background(Color(.tertiarySystemBackground))
200+
.background(.background.tertiary)
202201
.cornerRadius(8)
203202
}
204203
}

Examples/CharacterGenerator/CharacterGenerator/CharacterGenerator/Player/PlayerListView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ struct PlayerListView: View {
3232
}
3333
.navigationTitle("Characters")
3434
.toolbar {
35-
ToolbarItem(placement: .navigationBarLeading) {
35+
ToolbarItem(placement: .topBarLeading) {
3636
EditButton()
3737
}
3838

39-
ToolbarItem(placement: .navigationBarTrailing) {
39+
ToolbarItem(placement: .topBarTrailing) {
4040
Button {
4141
appState.addNewCharacter()
4242
if let newPlayer = appState.players[0] {

Sources/RolePlayingCore/Currency/UnitCurrency.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ public final class UnitCurrency : Dimension, @unchecked Sendable {
4343
super.init(symbol: symbol, converter: converter)
4444
}
4545

46-
// TODO: In order to provide the other init method, I was required to implement
47-
// this one as well. However, I don't know how to reconcile NSCoder with Codable.
46+
// MARK: NSCoding Support
47+
48+
/// Required initializer for NSCoding support, because `Dimension` conforms to `NSSecureCoding`.
49+
/// Since this class has a custom initializer, Swift requires all designated initializers from the superclass.
50+
///
51+
/// This library actually uses `Codable` for serialization (see below).
4852
public required init?(coder aDecoder: NSCoder) {
4953
super.init(coder: aDecoder)
5054
}

0 commit comments

Comments
 (0)