Created
August 10, 2016 20:46
-
-
Save chadaustin/2a05224e0f3442960359797b74b27aab 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
// | |
// main.swift | |
// memsafe | |
// | |
// Created by Chad Austin on 8/10/16. | |
// Copyright © 2016 Chad Austin. All rights reserved. | |
// | |
import Foundation | |
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT | |
let queue = dispatch_get_global_queue(priority, 0) | |
class Bird { | |
init(n: Int) { | |
self.n = n | |
} | |
private let n: Int | |
} | |
enum Variant { | |
case V1(Bird) | |
case V2(Double) | |
} | |
var single = Variant.V2(5) | |
dispatch_async(queue) { | |
while true { | |
switch single { | |
case .V1(let b): | |
print(b.n) | |
case .V2(let n): | |
print(n) | |
} | |
} | |
} | |
while true { | |
if drand48() < 0.5 { | |
single = .V1(Bird(n: 15)) | |
} else { | |
single = .V2(1.0 / 3.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment