Latest 3.0
Homepage https://github.com/robrix/Box
License MIT
Platforms ios 8.0
Authors

Box

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 one case has a value

Use

Wrapping & unwrapping a Box:

// Wrap:
let box = Box(1)

// Unwrap:
let value = box.value

Changing the value of a MutableBox:

// Mutation:
let mutableBox = MutableBox(1)
mutableBox.value = 2

Building a recursive value type:

struct BinaryTree {
    let value: Int
    let left: Box<BinaryTree>?
    let right: Box<BinaryTree>?
}

Building a parameterized enum:

enum Result<T> {
    case Success(Box<T>)
    case Failure(NSError)
}

See the sources for more details.

Integration

  1. Add this repo as a submodule in e.g. External/Box:

    git submodule add https://github.com/robrix/Box.git External/Box
  2. Drag Box.xcodeproj into your .xcworkspace/.xcodeproj.
  3. Add Box.framework to your target’s Link Binary With Libraries build phase.
  4. You may also want to add a Copy Files phase which copies Box.framework (and any other framework dependencies you need) into your bundle’s Frameworks directory. If your target is a framework, you may instead want the client app to include Box.framework.

Latest podspec

{
    "name": "BoxPod",
    "version": "3.0",
    "summary": "Swift u00b5framework of the ubiquitous Box & MutableBox reference types, for recursive value types & misc. other purposes.",
    "homepage": "https://github.com/robrix/Box",
    "license": "MIT",
    "authors": {
        "robrix": "[email protected]"
    },
    "source": {
        "git": "https://github.com/robrix/Box.git",
        "tag": "3.0"
    },
    "source_files": "Box/**/*.{h,swift}",
    "platforms": {
        "ios": "8.0"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This