Create a gist now

Instantly share code, notes, and snippets.

Playground contents demonstrating one way to get NSURL's associated with raw enumerations.
import Foundation
public enum Region: String {
static var _regionURLCache = [String: NSURL]();
case One = "http://region.meh/one";
case Two = "http://region.meh/two";
case Three = "http://region.meh/three";
public func URL() -> NSURL? {
var url: NSURL? = Region._regionURLCache[self.rawValue]
if (url == nil) {
url = NSURL(string: self.rawValue)
Region._regionURLCache[self.rawValue] = url
return url
for region in [Region.One, Region.Two, Region.Three] {
switch(region) {
case .One:
case .Two:
case .Three:
Region.One.URL() === Region.One.URL()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment