Created
June 15, 2018 10:11
-
-
Save onmyway133/b19bdccb5c9787da53fd0f03be672b05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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