From 1477085480522bd4ecd5ad8bc94e93fb62d8c9b8 Mon Sep 17 00:00:00 2001 From: mntone <901816+mntone@users.noreply.github.com> Date: Fri, 5 Jan 2024 00:40:23 +0900 Subject: [PATCH] Adds sort extensions. --- .../ViewModels/Utils/Sort+Extensions.swift | 25 +++++++++++++++++++ .../Modifiers/SharedMonsterListModifier.swift | 6 ++--- src/Core/StarSwings/Enums/Sort.swift | 1 - src/MonsterAnalyzer.xcodeproj/project.pbxproj | 6 +++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/App/ViewModels/Utils/Sort+Extensions.swift diff --git a/src/App/ViewModels/Utils/Sort+Extensions.swift b/src/App/ViewModels/Utils/Sort+Extensions.swift new file mode 100644 index 0000000..cc3b7f6 --- /dev/null +++ b/src/App/ViewModels/Utils/Sort+Extensions.swift @@ -0,0 +1,25 @@ +import enum MonsterAnalyzerCore.Sort + +extension Sort { + var label: String { + switch self { + case .inGame: + String(localized: "In Game", comment: "Sort/In Game") + case .name: + String(localized: "Name", comment: "Sort/Name") + case .type: + String(localized: "Type", comment: "Sort/Type") + } + } +} + +// MARK: - Identifiable + +extension Sort: Identifiable { + public var id: String { + @inline(__always) + get { + rawValue + } + } +} diff --git a/src/App/Views/Modifiers/SharedMonsterListModifier.swift b/src/App/Views/Modifiers/SharedMonsterListModifier.swift index 6116bb2..3af687a 100644 --- a/src/App/Views/Modifiers/SharedMonsterListModifier.swift +++ b/src/App/Views/Modifiers/SharedMonsterListModifier.swift @@ -12,9 +12,9 @@ struct SharedMonsterListModifier: ViewModifier { ToolbarItem(placement: .primaryAction) { Menu("Sort", systemImage: "arrow.up.arrow.down.circle") { Picker(selection: sort) { - Text("In Game", comment: "Sort/In Game").tag(Sort.inGame) - Text("Name", comment: "Sort/Name").tag(Sort.name) - Text("Type", comment: "Sort/Type").tag(Sort.type) + ForEach(Sort.allCases) { item in + Text(verbatim: item.label).tag(item) + } } label: { EmptyView() } diff --git a/src/Core/StarSwings/Enums/Sort.swift b/src/Core/StarSwings/Enums/Sort.swift index f5dee5b..98e62b0 100644 --- a/src/Core/StarSwings/Enums/Sort.swift +++ b/src/Core/StarSwings/Enums/Sort.swift @@ -1,4 +1,3 @@ -import Foundation public enum Sort: String, CaseIterable, Hashable, UserDefaultable { case inGame = "in_game" diff --git a/src/MonsterAnalyzer.xcodeproj/project.pbxproj b/src/MonsterAnalyzer.xcodeproj/project.pbxproj index ee165e5..a5f5126 100644 --- a/src/MonsterAnalyzer.xcodeproj/project.pbxproj +++ b/src/MonsterAnalyzer.xcodeproj/project.pbxproj @@ -175,6 +175,8 @@ EBBBAAB92B3FDE8D00BBAB23 /* Publishers+CombineLatestCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBBAAB82B3FDE8D00BBAB23 /* Publishers+CombineLatestCollection.swift */; }; EBBBAABA2B3FE27000BBAB23 /* GameGroupViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBDFD8502B3C112A00AF1832 /* GameGroupViewModel.swift */; }; EBBF861E2B46546400F76D03 /* JapaneseTextProcessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBF861D2B46546400F76D03 /* JapaneseTextProcessorTests.swift */; }; + EBBF86202B4692D500F76D03 /* Sort+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBF861F2B4692D500F76D03 /* Sort+Extensions.swift */; }; + EBBF86212B4692D500F76D03 /* Sort+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBF861F2B4692D500F76D03 /* Sort+Extensions.swift */; }; EBBF86242B46D4F000F76D03 /* FavoriteSwipeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBF86232B46D4F000F76D03 /* FavoriteSwipeButton.swift */; }; EBBF86252B46D4F000F76D03 /* FavoriteSwipeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBBF86232B46D4F000F76D03 /* FavoriteSwipeButton.swift */; }; EBC85C612B201939008A16C6 /* InfoPlist.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = EBC85C602B201939008A16C6 /* InfoPlist.xcstrings */; }; @@ -453,6 +455,7 @@ EBBBAAB62B3FCB0200BBAB23 /* libswiftWatchKit.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libswiftWatchKit.tbd; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS10.2.sdk/usr/lib/swift/libswiftWatchKit.tbd; sourceTree = DEVELOPER_DIR; }; EBBBAAB82B3FDE8D00BBAB23 /* Publishers+CombineLatestCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publishers+CombineLatestCollection.swift"; sourceTree = ""; }; EBBF861D2B46546400F76D03 /* JapaneseTextProcessorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JapaneseTextProcessorTests.swift; sourceTree = ""; }; + EBBF861F2B4692D500F76D03 /* Sort+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sort+Extensions.swift"; sourceTree = ""; }; EBBF86232B46D4F000F76D03 /* FavoriteSwipeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteSwipeButton.swift; sourceTree = ""; }; EBC85C602B201939008A16C6 /* InfoPlist.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = InfoPlist.xcstrings; sourceTree = ""; }; EBC85C702B2053B6008A16C6 /* WatchDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchDevice.swift; sourceTree = ""; }; @@ -796,6 +799,7 @@ children = ( EBB4B1E42B16A6D4004D63EA /* Attack+Extensions.swift */, EBDEEF392B3E3E5800835CBC /* DebounceNotifier.swift */, + EBBF861F2B4692D500F76D03 /* Sort+Extensions.swift */, EB693EA62B3B9F9700CDEC6F /* StarSwingsError+Extensions.swift */, EB6437932B46EF5400E8D02B /* SwipeAction+Extensions.swift */, EB99DBCC2B36D16B00A43552 /* WeaknessDisplayMode+Extensions.swift */, @@ -1319,6 +1323,7 @@ EB97F6A62B31B60700E31602 /* SharedMonsterListModifier.swift in Sources */, EB3B49232B35EAD100E89711 /* SharedSettingsContainerModifier.swift in Sources */, EB6ADE752B3660340010BD64 /* SharedSettingsPaneModifier.swift in Sources */, + EBBF86212B4692D500F76D03 /* Sort+Extensions.swift in Sources */, EB693EA82B3B9F9700CDEC6F /* StarSwingsError+Extensions.swift in Sources */, EB967A4C2B2AC7100041A491 /* StateView.swift in Sources */, EB560BD52B4386D700E91E01 /* StatusOverlayModifier.swift in Sources */, @@ -1479,6 +1484,7 @@ EB3B49222B35EAD100E89711 /* SharedSettingsContainerModifier.swift in Sources */, EB6ADE742B3660340010BD64 /* SharedSettingsPaneModifier.swift in Sources */, EB645A642B2685D500D27500 /* Sidebar.swift in Sources */, + EBBF86202B4692D500F76D03 /* Sort+Extensions.swift in Sources */, EB693EA72B3B9F9700CDEC6F /* StarSwingsError+Extensions.swift in Sources */, EB967A4B2B2AC7100041A491 /* StateView.swift in Sources */, EB560BD42B4386D700E91E01 /* StatusOverlayModifier.swift in Sources */,