Skip to content

Instantly share code, notes, and snippets.

@daoseng33
Created June 28, 2018 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daoseng33/a82cbfae6fe50028a426a41bfe2cb6d2 to your computer and use it in GitHub Desktop.
Save daoseng33/a82cbfae6fe50028a426a41bfe2cb6d2 to your computer and use it in GitHub Desktop.
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