Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created October 26, 2023 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/b6ce5db2470aeabcf2f8e936cb3a5725 to your computer and use it in GitHub Desktop.
Save JadenGeller/b6ce5db2470aeabcf2f8e936cb3a5725 to your computer and use it in GitHub Desktop.
Box
@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