Created
June 28, 2018 13:15
-
-
Save daoseng33/a82cbfae6fe50028a426a41bfe2cb6d2 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
enum Type: String { | |
// 直接指定 API 回傳的 String | |
case regular = "regular" | |
case system = "system" | |
case advertise = "advertise" | |
var image: UIImage? { | |
// 一行搞定 | |
return UIImage(named: self.rawValue) | |
} | |
} | |
let imageView = UIImageView() | |
let json = ["type": "regular"] | |
if let typeString = json["type"] { | |
imageView.image = Type(rawValue: typeString)?.image | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment