userdefault

⚙️ A tiny property wrapper for UserDefaults. Only 60 lines of code. (by mezhevikin)

Userdefault Alternatives

Similar projects and alternatives to userdefault based on common topics and language

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a better userdefault alternative or higher similarity.

userdefault reviews and mentions

Posts with mentions or reviews of userdefault. We have used some of these posts to build our list of alternatives and similar projects.
  • A tiny property wrapper for UserDefaults with improved performance
    1 project | /r/swift | 5 Sep 2022
    // Mezhevikin Alexey: https://github.com/mezhevikin/userdefault import Foundation import Combine @propertyWrapper public struct UserDefault { private let key: String private var value: Value private let defaultValue: Value private var container: UserDefaults = .standard private let publisher = PassthroughSubject() public init( _ key: String, _ defaultValue: Value, _ container: UserDefaults = .standard ) { self.key = key self.value = container.object(forKey: key) as? Value ?? defaultValue self.defaultValue = defaultValue self.container = container } public var wrappedValue: Value { get { value } set { value = newValue if let optional = value as? AnyOptional, optional.isNil { container.removeObject(forKey: key) } else { container.set(value, forKey: key) } publisher.send(value) } } public var projectedValue: AnyPublisher { publisher.eraseToAnyPublisher() } } public protocol AnyOptional { var isNil: Bool { get } } extension Optional: AnyOptional { public var isNil: Bool { self == nil } } extension UserDefault where Value: ExpressibleByNilLiteral { public init(_ key: String, _ container: UserDefaults = .standard) { self.init(key, nil, container) } }

Stats

Basic userdefault repo stats
1
0
10.0
over 1 year ago

mezhevikin/userdefault is an open source project licensed under MIT License which is an OSI approved license.

The primary programming language of userdefault is Swift.

Popular Comparisons


Sponsored
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com