Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created June 15, 2018 08:34
Show Gist options
  • Save onmyway133/10afdea56cb50b03ea1b0271d9176124 to your computer and use it in GitHub Desktop.
Save onmyway133/10afdea56cb50b03ea1b0271d9176124 to your computer and use it in GitHub Desktop.
public extension StorageAware {
func object<T: Codable>(ofType type: T.Type, forKey key: String) throws -> T {
return try entry(ofType: type, forKey: key).object
}
func existsObject<T: Codable>(ofType type: T.Type, forKey key: String) throws -> Bool {
do {
let _: T = try object(ofType: type, forKey: key)
return true
} catch {
return false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment