Giter Site home page Giter Site logo

ikesyo / box Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robrix/box

0.0 3.0 0.0 49 KB

Swift µframework of the ubiquitous Box<T> & MutableBox<T> reference types, for recursive value types & misc. other purposes.

License: MIT License

C++ 4.77% Swift 95.23%

box's Introduction

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.

box's People

Contributors

gfontenot avatar jaspa avatar jspahrsummers avatar robrix avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.