This is a Swift microframework which implements Box<T> & MutableBox<T>, with implementations of ==/!= where T: Equatable.
Box is typically used to work around limitations of value types:
- recursive
structs/enums - type-parameterized
enums where more than onecasehas a value
Wrapping & unwrapping a Box:
// Wrap: letbox=Box(1) // Unwrap: letvalue= box.valueChanging the value of a MutableBox:
// Mutation: letmutableBox=MutableBox(1) mutableBox.value =2Building a recursive value type:
structBinaryTree{letvalue:Intletleft:Box<BinaryTree>?letright:Box<BinaryTree>?}Building a parameterized enum:
enumResult<T>{case Success(Box<T>)case Failure(NSError)}See the sources for more details.
Add this repo as a submodule in e.g.
External/Box:git submodule add https://github.com/robrix/Box.git External/BoxDrag
Box.xcodeprojinto your.xcworkspace/.xcodeproj.Add
Box.frameworkto your target’sLink Binary With Librariesbuild phase.You may also want to add a
Copy Filesphase which copiesBox.framework(and any other framework dependencies you need) into your bundle’sFrameworksdirectory. If your target is a framework, you may instead want the client app to includeBox.framework.