Skip to content

⚙️ A tiny property wrapper for UserDefaults. Only 60 lines of code.

License

Notifications You must be signed in to change notification settings

mezhevikin/Persistent

Repository files navigation

⚙️ A tiny property wrapper for UserDefaults. Only 60 lines of code.

import Persistent

extension UserDefaults {
    
    // Optional property
    @Persistent("login", .standard)
    static var login: String?
    
    // Property with default value
    @Persistent("isDarkMode", false)
    static var isDarkMode: Bool
}
UserDefaults.login = "mezhevikin"
UserDefaults.isDarkMode = true

Combine

let subscription = UserDefaults.$isDarkMode.sink {
    print($0)
}
UserDefaults.isDarkMode = true

Swift Package Manager

https://github.com/mezhevikin/persistent.git

Inspired Antonie Van Der Lee