-
-
Save akio0911/f3837d445891f182de71186a27e429ae 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
// ZMapTable.swift | |
// | |
// Copyright (c) 2016 Kaz Yoshikawa. Released under MIT License. | |
enum ZMapTableOption { | |
case StrongToWeak | |
case WeakToStrong | |
case WeakToWeak | |
case StrongToStrong | |
var creator: () -> NSMapTable { | |
switch self { | |
case .StrongToWeak: return NSMapTable.strongToWeakObjectsMapTable | |
case .WeakToStrong: return NSMapTable.weakToStrongObjectsMapTable | |
case .WeakToWeak: return NSMapTable.weakToWeakObjectsMapTable | |
case .StrongToStrong: return NSMapTable.strongToStrongObjectsMapTable | |
} | |
} | |
} | |
class ZMapTable<K: AnyObject, V: AnyObject>: CustomStringConvertible { | |
let mapTable: NSMapTable | |
init(option: ZMapTableOption) { | |
mapTable = option.creator() | |
} | |
subscript(key: K) -> V? { | |
get { return self.mapTable.objectForKey(key) as? V } | |
set { self.mapTable.setObject(newValue, forKey: key) } | |
} | |
var description: String { | |
return self.mapTable.description | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment