Coder Social home page Coder Social logo

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

argon avatar gfontenot avatar jaspa avatar jspahrsummers avatar kennytm avatar robrix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

box's Issues

Compilation error using carthage

Hi... just tried to add Box to a brand new project using Carthage (my cartfile contains github "robrix/Box" ~> 1.2.0) and get the following error when I run carthage update:

clang: error: invalid architecture 'aarch64' for deployment target '-mios-simulator-version-min=8.0'

If I manually open and build Carthage/Checkouts/Box/Box.xcodeproj in Xcode (6.3, if it matters) it compiles OK. The one difference that I can see between the two compilation commands are that carthage is using Release-iphoneos, whereas Xcode uses Debug-iphonesimulator.

The full transcript of the carthage build is https://gist.github.com/edwardaux/8a2319844ba00582c0b7

Any thoughts? Thanks.

Repeated build errors

Running into errors with building box (2.0 and 1.2.2) on my system (OS X 10.10.5) after installing Xcode 7.0. (but manually reverting to 6.4)

$ xcode-select -p
/Applications/Xcode 6.4.app/Contents/Developer

$ xcodebuild -version
Xcode 6.4
Build version 6E35b

$ cat Cartfile 
github "robrix/Box" "2.0"

$ carthage bootstrap

carthage bootstrap
*** Checking out Box at "2.0"
*** xcodebuild output can be found in /var/folders/jv/5fg0gqbd6gj861f82prqvw240000gp/T/carthage-xcodebuild.3SM7TP.log
*** Building scheme "Box-Mac" in Box.xcodeproj
** BUILD FAILED **


The following build commands failed:
    CompileSwift normal x86_64 <project-dir>/Carthage/Checkouts/Box/Box/Box.swift
    CompileSwift normal x86_64 <project-dir>/Carthage/Checkouts/Box/Box/MutableBox.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(3 failures)
<project-dir>/Carthage/Checkouts/Box/Box/Box.swift:6:37: error: use of undeclared type 'CustomStringConvertible'
<project-dir>/Carthage/Checkouts/Box/Box/Box.swift:31:17: error: missing argument label 'stringInterpolationSegment:' in call
<project-dir>/Carthage/Checkouts/Box/Box/MutableBox.swift:8:51: error: use of undeclared type 'CustomStringConvertible'
<project-dir>/Carthage/Checkouts/Box/Box/MutableBox.swift:25:17: error: missing argument label 'stringInterpolationSegment:' in call
A shell task failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
    CompileSwift normal x86_64 <project-dir>/Carthage/Checkouts/Box/Box/Box.swift
    CompileSwift normal x86_64 <project-dir>/Carthage/Checkouts/Box/Box/MutableBox.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(3 failures)

$ cat /var/folders/jv/5fg0gqbd6gj861f82prqvw240000gp/T/carthage-xcodebuild.3SM7TP.log
<project-dir>/Carthage/Checkouts/Box/Box/Box.swift:6:37: error: use of undeclared type 'CustomStringConvertible'
public final class Box<T>: BoxType, CustomStringConvertible {
                                    ^~~~~~~~~~~~~~~~~~~~~~~
<project-dir>/Carthage/Checkouts/Box/Box/Box.swift:31:17: error: missing argument label 'stringInterpolationSegment:' in call
                return String(value)
                              ^
                              stringInterpolationSegment: 

[snip]

<project-dir>/Carthage/Checkouts/Box/Box/MutableBox.swift:8:51: error: use of undeclared type 'CustomStringConvertible'
public final class MutableBox<T>: MutableBoxType, CustomStringConvertible {
                                                  ^~~~~~~~~~~~~~~~~~~~~~~
<project-dir>/Carthage/Checkouts/Box/Box/MutableBox.swift:25:17: error: missing argument label 'stringInterpolationSegment:' in call
                return String(value)
                              ^
                              stringInterpolationSegment: 

Tag new version?

Since Box now has an iOS scheme in addition to the OS X scheme (and the deployment target for OS X has been lowered), should we have a new tagged version?

Deadlocks when instantiating recursive struct (such as BinaryTree<T>).

Instantiating a "boxed" recursive struct (like the one described in README) results in a deadlock.

import Cocoa
import Box

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

typealias Tree = BinaryTree<Int>
typealias TreeBox = Box<Tree>

let left = Tree(value: 1, left: nil, right: nil)
let right = Tree(value: 3, left: nil, right: nil)
let root = Tree(value: 2, left: TreeBox(left), right: TreeBox(right))

The process gets trapped right at/before let left = …

Am I being silly here or is this a Swift bug as I reckon?

Support iOS7

Some of us poor souls are forced to support iOS7. Bumping the deployment target down to 7.0 would bring a little joy into our otherwise miserable existence.

Swift 2 protocols renamed

When building with base SDK set to iOS 9, build errors arise since Printable has been renamed to CustomStringConvertible and toString to String.

Update cocoapod

I'm getting this error 'Printable' has been renamed to 'CustomStringConvertible' can you update cocoapod?

map()

func map<T, U>(Box<T>, T -> U) -> Box<U>

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.