From 46c5399b36144757d6b4452938887fda0ba4154d Mon Sep 17 00:00:00 2001 From: Matt Kiazyk Date: Wed, 23 Dec 2020 16:20:03 -0600 Subject: [PATCH 1/2] Saves the list category to userdefaults on top tab --- Xcodes/Frontend/XcodeList/XcodeListView.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Xcodes/Frontend/XcodeList/XcodeListView.swift b/Xcodes/Frontend/XcodeList/XcodeListView.swift index c6ab09a..e8dc8cd 100644 --- a/Xcodes/Frontend/XcodeList/XcodeListView.swift +++ b/Xcodes/Frontend/XcodeList/XcodeListView.swift @@ -6,9 +6,10 @@ struct XcodeListView: View { @EnvironmentObject var appState: AppState @State private var selection = Set() @State private var rowBeingConfirmedForUninstallation: AppState.XcodeVersion? - @State private var category: Category = .all @State private var searchText: String = "" + @AppStorage("listCategory") private var category: Category = .all + var visibleVersions: [AppState.XcodeVersion] { var versions: [AppState.XcodeVersion] switch category { @@ -25,8 +26,9 @@ struct XcodeListView: View { return versions } - enum Category { - case all, installed + enum Category: String, CaseIterable { + case all = "All" + case installed = "Installed" } var body: some View { @@ -79,10 +81,9 @@ struct XcodeListView: View { } ToolbarItem(placement: .principal) { Picker("", selection: $category) { - Text("All") - .tag(Category.all) - Text("Installed") - .tag(Category.installed) + ForEach(Category.allCases, id: \.self) { + Text($0.rawValue).tag($0) + } } .pickerStyle(SegmentedPickerStyle()) } From 583eb8b2b84b85db07db94662d3351df57dd22a5 Mon Sep 17 00:00:00 2001 From: Matt Kiazyk Date: Sun, 27 Dec 2020 08:49:15 -0600 Subject: [PATCH 2/2] PR List tab Tweaks --- Xcodes/Frontend/XcodeList/XcodeListView.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Xcodes/Frontend/XcodeList/XcodeListView.swift b/Xcodes/Frontend/XcodeList/XcodeListView.swift index e8dc8cd..6c27885 100644 --- a/Xcodes/Frontend/XcodeList/XcodeListView.swift +++ b/Xcodes/Frontend/XcodeList/XcodeListView.swift @@ -8,7 +8,7 @@ struct XcodeListView: View { @State private var rowBeingConfirmedForUninstallation: AppState.XcodeVersion? @State private var searchText: String = "" - @AppStorage("listCategory") private var category: Category = .all + @AppStorage("xcodeListCategory") private var category: Category = .all var visibleVersions: [AppState.XcodeVersion] { var versions: [AppState.XcodeVersion] @@ -26,9 +26,18 @@ struct XcodeListView: View { return versions } - enum Category: String, CaseIterable { - case all = "All" - case installed = "Installed" + enum Category: String, CaseIterable, Identifiable, CustomStringConvertible { + case all + case installed + + var id: Self { self } + + var description: String { + switch self { + case .all: return "All" + case .installed: return "Installed" + } + } } var body: some View { @@ -82,7 +91,7 @@ struct XcodeListView: View { ToolbarItem(placement: .principal) { Picker("", selection: $category) { ForEach(Category.allCases, id: \.self) { - Text($0.rawValue).tag($0) + Text($0.description).tag($0) } } .pickerStyle(SegmentedPickerStyle())