From 60083940e57041bcf7ac39beda67bca1705b6346 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Jan 2026 14:30:07 -0600 Subject: [PATCH] Add DemoDestination; Remove DemoDestination --- SecureStorageSample/ContentView.swift | 105 ++++++++++++++++---------- 1 file changed, 65 insertions(+), 40 deletions(-) diff --git a/SecureStorageSample/ContentView.swift b/SecureStorageSample/ContentView.swift index 0c21cd2..cdda322 100644 --- a/SecureStorageSample/ContentView.swift +++ b/SecureStorageSample/ContentView.swift @@ -8,28 +8,75 @@ import SwiftUI import LocalData +private enum DemoDestination: Hashable, CaseIterable { + case userDefaults + case keychain + case files + case encrypted + case sync + case migration + + var view: some View { + switch self { + case .userDefaults: + return AnyView(UserDefaultsDemo()) + case .keychain: + return AnyView(KeychainDemo()) + case .files: + return AnyView(FileSystemDemo()) + case .encrypted: + return AnyView(EncryptedStorageDemo()) + case .sync: + return AnyView(PlatformSyncDemo()) + case .migration: + return AnyView(MigrationHubView()) + } + } + + var title: String { + switch self { + case .userDefaults: + return "UserDefaults" + case .keychain: + return "Keychain" + case .files: + return "File Storage" + case .encrypted: + return "Encrypted Storage" + case .sync: + return "Watch Sync" + case .migration: + return "Migrations" + } + } + + var systemImage: String { + switch self { + case .userDefaults: + return "gearshape.fill" + case .keychain: + return "lock.fill" + case .files: + return "doc.fill" + case .encrypted: + return "lock.shield.fill" + case .sync: + return "arrow.triangle.2.circlepath" + case .migration: + return "sparkles" + } + } +} + struct ContentView: View { var body: some View { NavigationStack { List { Section("Storage Demos") { - NavigationLink(value: DemoDestination.userDefaults) { - Label("UserDefaults", systemImage: "gearshape.fill") - } - NavigationLink(value: DemoDestination.keychain) { - Label("Keychain", systemImage: "lock.fill") - } - NavigationLink(value: DemoDestination.files) { - Label("File Storage", systemImage: "doc.fill") - } - NavigationLink(value: DemoDestination.encrypted) { - Label("Encrypted Storage", systemImage: "lock.shield.fill") - } - NavigationLink(value: DemoDestination.sync) { - Label("Watch Sync", systemImage: "arrow.triangle.2.circlepath") - } - NavigationLink(value: DemoDestination.migration) { - Label("Migrations", systemImage: "sparkles") + ForEach(DemoDestination.allCases, id: \.self) { demo in + NavigationLink(value: demo) { + Label(demo.title, systemImage: demo.systemImage) + } } } } @@ -37,20 +84,7 @@ struct ContentView: View { .navigationTitle("Secure Storage") .navigationBarTitleDisplayMode(.inline) .navigationDestination(for: DemoDestination.self) { destination in - switch destination { - case .userDefaults: - UserDefaultsDemo() - case .keychain: - KeychainDemo() - case .files: - FileSystemDemo() - case .encrypted: - EncryptedStorageDemo() - case .sync: - PlatformSyncDemo() - case .migration: - MigrationHubView() - } + return destination.view } } } @@ -59,12 +93,3 @@ struct ContentView: View { #Preview { ContentView() } - -private enum DemoDestination: Hashable { - case userDefaults - case keychain - case files - case encrypted - case sync - case migration -}