Last active
October 14, 2017 11:58
-
-
Save reejosamuel/164c9c98a380aab352eb2fc684f034bc to your computer and use it in GitHub Desktop.
Implementing a simple string cache
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
class StringCache: NSCache<NSString, String> { | |
static let shared = ImageCache() | |
func set(_ text: String, for keyString: String) { | |
self.setObject(text, forKey: keyString as NSString) | |
} | |
func textFrom(_ keyString: String?) -> String? { | |
guard let keyString = keyString else { | |
return nil | |
} | |
return self.object(forKey: keyString as NSString) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment