Created
October 26, 2023 19:51
-
-
Save JadenGeller/b6ce5db2470aeabcf2f8e936cb3a5725 to your computer and use it in GitHub Desktop.
Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct Box<T> { | |
class Storage { | |
var value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
} | |
private let storage: Storage | |
var wrappedValue: T { | |
get { storage.value } | |
nonmutating set { storage.value = newValue } | |
} | |
init(wrappedValue: T) { | |
storage = Storage(wrappedValue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment