Created
June 27, 2014 16:50
-
-
Save Nub/e2a3165252fb4b2404b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import Cocoa | |
struct MagicNumber { | |
var skip: Bool = false | |
var f: Float? { | |
didSet { | |
if skip {skip = false; return} | |
skip = true | |
i = Int(f!) | |
} | |
} | |
var i: Int?{ | |
didSet { | |
if skip {skip = false; return} | |
skip = true | |
f = Float(i!) | |
} | |
} | |
func value() -> AnyObject { | |
if let f = f { | |
return f | |
} | |
if let i = i { | |
return i | |
} | |
return NSNull() | |
} | |
init (float: Float) { | |
f = float | |
} | |
init (int: Int) { | |
i = int | |
} | |
} | |
var a = MagicNumber(int: 1) | |
var b = MagicNumber(float: 1.5) | |
a.value() | |
b.value() | |
a.i = 2 | |
a.f = 5.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment