Skip to content

Instantly share code, notes, and snippets.

@inamiy
Created February 9, 2021 06:23
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inamiy/98575ec47e06b0cd52efbdec0e0c2b52 to your computer and use it in GitHub Desktop.
Save inamiy/98575ec47e06b0cd52efbdec0e0c2b52 to your computer and use it in GitHub Desktop.
Recursive struct in Swift using Box (indirect struct)
@propertyWrapper
class Box<T> {
var wrappedValue: T
var projectedValue: Box<T> {
Box(wrappedValue)
}
init(_ value: T) {
self.wrappedValue = value
}
}
struct Foo {
@Box
var foo: Foo
}
// SeeAlso: https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md#ref--box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment