Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created June 15, 2018 10:11
Show Gist options
  • Save onmyway133/b19bdccb5c9787da53fd0f03be672b05 to your computer and use it in GitHub Desktop.
Save onmyway133/b19bdccb5c9787da53fd0f03be672b05 to your computer and use it in GitHub Desktop.
// WARNING: Does not compile
extension Storage {
func save(object: Any, forKey: String) {
switch object {
case let image as Image:
let data = UIImagePNGRepresentation(image)
case let object as Codable:
let encoder = JSONEncoder()
try? encoder.encode(object) // Cannot invoke 'encode' with an argument list of type '(Codable)'
default:
break
}
}
}
storage.save(15, forKey: "number")
storage.save(image, forKey: "image")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment