Create a gist now

Instantly share code, notes, and snippets.

Playground contents demonstrating an ugly, but, ultimately works just fine, approach to raw enums with structs for values
import Foundation
public struct RegionStruct: StringLiteralConvertible, Equatable {
let name: String
let platformId: String
let host: NSURL
typealias UnicodeScalarLiteralType = Character
/// Create an instance initialized to `value`.
public init(unicodeScalarLiteral value: Character) {
self.init(stringLiteral: String(value))
typealias ExtendedGraphemeClusterLiteralType = String
public init(extendedGraphemeClusterLiteral value: String) {
self.init(stringLiteral: value)
typealias StringLiteralType = String
public init(stringLiteral value: String) {
let parts = value.componentsSeparatedByString(" ")
self.init(name: parts[0], platformId: parts[1], host: NSURL(string: parts[2])!)
public init(name: String, platformId: String, host: NSURL) { = name
self.platformId = platformId = host
public func ==(lhs: RegionStruct, rhs: RegionStruct) -> Bool {
let computedLhs = "\( \(lhs.platformId) \("
let computedRhs = "\( \(rhs.platformId) \("
return computedLhs == computedRhs
let x: RegionStruct = "name0 plaf0 http://x.y/0"
public enum Region: RegionStruct {
case One = "nameOne plafOne";
case Two = "nameTwo plafTwo http://two.two/two";
case Three = "nameThree plafThree http://three.three/three";
for region in [Region.One, Region.Two, Region.Three] {
switch(region) {
case .One:
case .Two:
case .Three:
Region.One.rawValue == Region.One.rawValue
Region.Two.rawValue == Region.One.rawValue
let r = Region(rawValue: Region.One.rawValue)
r == Region.One
let rs: RegionStruct = RegionStruct(name: "nameOne", platformId: "plafOne", host: NSURL(string: "")!)
Region.One == Region(rawValue: rs)
ztj commented Mar 7, 2015

Some elements could be implemented better in production code. This is an example. It is a starting point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment