Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created July 10, 2014 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/2369635866aa86281d9d to your computer and use it in GitHub Desktop.
Save Pretz/2369635866aa86281d9d to your computer and use it in GitHub Desktop.
parameterized enums in swift that don't crash xcode
// 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