Skip to content

Instantly share code, notes, and snippets.

@revblaze
Created July 8, 2021 17:34
Show Gist options
  • Save revblaze/b999020df1452f654c5b4af45a00ab3d to your computer and use it in GitHub Desktop.
Save revblaze/b999020df1452f654c5b4af45a00ab3d to your computer and use it in GitHub Desktop.
Quick, typesafe SF Symbols extension for Swift(UI)
enum Symbol: String {
case add = "plus"
case trash = "trash"
case todo = "square"
case done = "checkmark.square"
}
/// Returns an image from the SF Symbols library
/// # Usage: Image(.trash) for Image(systemName: "trash")
extension Image {
init?(_ name: Symbol) {
self.init(systemName: name.rawValue)
}
}
// Check SFSymbols.swift for pre-symbol compatibility:
// https://gist.github.com/paulofierro/c035b67e5257444306eabc06054086e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment