Created
July 10, 2014 22:38
-
-
Save Pretz/2369635866aa86281d9d to your computer and use it in GitHub Desktop.
parameterized enums in swift that don't crash xcode
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 Foundation | |
struct ResultType<T: NSObject> { | |
var _value: [T] | |
var value: T { | |
get { | |
return _value[0] | |
} | |
set { | |
_value = [newValue] | |
} | |
} | |
init(value: T) { | |
_value = [value] | |
} | |
} | |
enum ApiResult<T: NSObject> { | |
case Success(ResultType<T>) | |
case Error(String, NSError) | |
} | |
func something(val: ApiResult<NSString>) { | |
switch val { | |
case .Success(let val2): | |
println(val2.value) | |
default: | |
println("wah wah") | |
} | |
} | |
let res2 = ApiResult<NSString>.Success(ResultType(value: NSString(string: "lololol"))) | |
something(res2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment