目录
目录README.md

SymbolMacro

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)],
)

Example

#symbol

let symbolName = #symbol("figure.walk")
// Expands to:
let symbolName = "figure.walk"
let symbolName = #symbol("figure.eating.beans")
// Error: 1:18 invalid symbol name

#symbolImage

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

Limitations

Symbol availability is based on the OS version of the device compiling an app, not the target deployment version of the app.

Alternatives

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.

关于
40.0 KB
邀请码