Compile-time checked SF Symbol names using Swift Macros
let package = Package(
name: "SymbolMacro",
platforms: [.iOS(.v13), .macOS(.v11), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
)
let symbolName = #symbol("figure.walk")
// Expands to:
let symbolName = "figure.walk"
let symbolName = #symbol("figure.eating.beans")
// Error: 1:18 invalid symbol name
let symbol = #symbolImage("figure.walk")
// Expands to:
let symbol = Image("figure.walk")
let symbol = #symbolImage("figure.eating.beans")
// Expands to:
// Error: 1:14 invalid symbol name
SF Symbols can be accessed using hardcoded enum cases using:
These give inline autocomplete of symbols, whereas SymbolMacro
is used with string literals that can be searched using the Xcode symbol library (⌘⇧L). SymbolMacro
avoids the requirement of needing to wait for a 3rd-party library to update when new symbols are released.