SymbolMacro

1.0.0

Compile-time checked SF Symbol names using Swift Macros
finnvoor/SymbolMacro

What's New

Version 1.0.0

2023-06-14T21:41:40Z

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.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • SwiftSyntax509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a
Last updated: Tue Apr 30 2024 13:25:06 GMT-0900 (Hawaii-Aleutian Daylight Time)