// Apple-only learning file: iOS 17+ target with a suitable Xcode SDK. // Not compiled or run in this Windows/Linux review. import SwiftUI import Security struct DemoView: View { @State private var notice = "No Keychain operation" private var key: [String: Any] { [kSecClass as String: kSecClassGenericPassword, kSecAttrService as String: "BhyluWorkshopTeaching", kSecAttrAccount as String: "demo-only"] } var body: some View { VStack(spacing: 20) { Button("Add fake demo value") { var item = key item[kSecValueData as String] = Data("not-a-real-secret".utf8) item[kSecAttrAccessible as String] = kSecAttrAccessibleWhenUnlockedThisDeviceOnly notice = "Add status: \(SecItemAdd(item as CFDictionary, nil))" } Button("Check demo item exists") { var query = key; query[kSecReturnAttributes as String] = true var result: CFTypeRef? notice = "Lookup status: \(SecItemCopyMatching(query as CFDictionary, &result))" } Button("Delete only this demo item", role: .destructive) { notice = "Delete status: \(SecItemDelete(key as CFDictionary))" } Text(notice) }.padding() } } @main struct WorkshopDemoApp: App { var body: some Scene { WindowGroup { DemoView() } } }