Last active
May 2, 2016 16:58
-
-
Save codelynx/cadf72f1bbba5f453dd9 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 | |
} | |
class ZMapTable<K: AnyObject, V: AnyObject>: CustomStringConvertible { | |
let mapTable: NSMapTable | |
init(option: ZMapTableOption) { | |
switch option { | |
case .StrongToWeak: self.mapTable = NSMapTable.strongToWeakObjectsMapTable() | |
case .WeakToStrong: self.mapTable = NSMapTable.weakToStrongObjectsMapTable() | |
case .WeakToWeak: self.mapTable = NSMapTable.weakToWeakObjectsMapTable() | |
case .StrongToStrong: self.mapTable = NSMapTable.strongToStrongObjectsMapTable() | |
} | |
} | |
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