44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
import Foundation
|
|
import LocalData
|
|
|
|
extension StorageKey where Value == String {
|
|
nonisolated static let legacyAppMode = StorageKey(
|
|
name: "legacy_app_mode",
|
|
domain: .userDefaults(suite: nil),
|
|
security: .none,
|
|
serializer: .json,
|
|
owner: "MigrationDemo",
|
|
description: "Legacy app mode stored in UserDefaults.",
|
|
availability: .all,
|
|
syncPolicy: .never
|
|
)
|
|
|
|
nonisolated static let modernAppMode = StorageKey(
|
|
name: "modern_app_mode",
|
|
domain: .keychain(service: "com.mbrucedogs.securestorage"),
|
|
security: .keychain(
|
|
accessibility: .afterFirstUnlock,
|
|
accessControl: .userPresence
|
|
),
|
|
serializer: .json,
|
|
owner: "MigrationDemo",
|
|
description: "Modern app mode with conditional migration.",
|
|
availability: .all,
|
|
syncPolicy: .never,
|
|
migration: { key in
|
|
let legacy = StorageKey.legacyAppMode
|
|
let fallback = AnyStorageMigration(
|
|
SimpleLegacyMigration(destinationKey: key, sourceKey: .key(legacy))
|
|
)
|
|
|
|
return AnyStorageMigration(
|
|
AppVersionConditionalMigration(
|
|
destinationKey: key,
|
|
minAppVersion: "99.0",
|
|
fallbackMigration: fallback
|
|
)
|
|
)
|
|
}
|
|
)
|
|
}
|