Skip to content

Commit

Permalink
Optimize Defaults property wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ktiays committed Oct 14, 2023
1 parent f6417a2 commit 5d76f50
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sources/CyanUtils/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ extension Data: ConstructibleFromDefaults {
public struct Defaults<T> where T: ConstructibleFromDefaults {

public let key: String
public let defaultValue: T
public var defaultValue: T {
`default`()
}
private let `default`: () -> T

public init(key: String, defaultValue: T) {
public init(key: String, default: @escaping () -> T) {
self.key = key
self.defaultValue = defaultValue
self.default = `default`
}

public init(key: String, defaultValue: T) {
self.init(key: key) { defaultValue }
}

public var wrappedValue: T {
Expand Down

0 comments on commit 5d76f50

Please sign in to comment.