Skip to content

SecureStorage is a property wrapper around the keychain to easily access your protected data.

License

Notifications You must be signed in to change notification settings

0xWDG/SecureStorage

Repository files navigation

SecureStorage

SecureStorage is a property wrapper around the keychain to easily access your protected data.

Swift Package Manager License

Requirements

  • Swift 5.9+ (Xcode 15+)
  • iOS 13+, macOS 10.15+

Installation (Pakage.swift)

dependencies: [
    .package(url: "https://github.com/0xWDG/SecureStorage.git", branch: "main"),
],
targets: [
    .target(name: "MyTarget", dependencies: [
        .product(name: "SecureStorage", package: "SecureStorage"),
    ]),
]

Installation (Xcode)

  1. In Xcode, open your project and navigate to FileSwift PackagesAdd Package Dependency...
  2. Paste the repository URL (https://github.com/0xWDG/SecureStorage) and click Next.
  3. Click Finish.

Usage

import SwiftUI
import SecureStorage

struct ContentView: View {
    // For this example, we directly bind the username & password.
    // This is not smart to do, because you'll overwrite the values as you type.
    @SecureStorage("username")
    var username: String?

    @SecureStorage("password")
    var password: String?

    var body: some View {
        VStack {
            Text("Please login")
            TextField("Username", text: $username ?? "")
            SecureField("Password", text: $password ?? "")

            Button("Login") {
                print("Login", username, password)
            }
            Button("Delete username") {
                SecureStorage("username").delete()
            }
            Button("Delete password") {
                SecureStorage("password").delete()
            }
            Button("Delete username") {
                SecureStorage("*").deleteAll()
            }
        }
    }
}

Contact

🦋 @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧵 @0xWDG 🌐 wesleydegroot.nl 🤖 Discord

Interested learning more about Swift? Check out my blog.

About

SecureStorage is a property wrapper around the keychain to easily access your protected data.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages