{"id":13479950,"url":"https://github.com/lukepistrol/SFSymbolsMacro","last_synced_at":"2025-03-27T10:30:55.665Z","repository":{"id":175291416,"uuid":"653651522","full_name":"lukepistrol/SFSymbolsMacro","owner":"lukepistrol","description":"A Swift Macro for \"type-safe\" SF Symbols.","archived":false,"fork":false,"pushed_at":"2025-01-23T18:41:28.000Z","size":31,"stargazers_count":191,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-21T15:14:51.082Z","etag":null,"topics":["swift","swift-macros","swift-package","swift-package-manager","swift5-9","swiftui","xcode15"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukepistrol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"lukepistrol","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["buymeacoffee.com/lukeeep"]}},"created_at":"2023-06-14T13:10:49.000Z","updated_at":"2025-03-12T16:45:41.000Z","dependencies_parsed_at":"2023-07-06T14:00:20.380Z","dependency_job_id":"695522cf-57b0-4d87-89a0-ef2225a48a43","html_url":"https://github.com/lukepistrol/SFSymbolsMacro","commit_stats":null,"previous_names":["lukepistrol/sfsymbolsmacro"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukepistrol%2FSFSymbolsMacro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukepistrol%2FSFSymbolsMacro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukepistrol%2FSFSymbolsMacro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukepistrol%2FSFSymbolsMacro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukepistrol","download_url":"https://codeload.github.com/lukepistrol/SFSymbolsMacro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245826752,"owners_count":20678851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swift","swift-macros","swift-package","swift-package-manager","swift5-9","swiftui","xcode15"],"created_at":"2024-07-31T17:00:28.856Z","updated_at":"2025-03-27T10:30:55.368Z","avatar_url":"https://github.com/lukepistrol.png","language":"Swift","funding_links":["https://github.com/sponsors/lukepistrol","buymeacoffee.com/lukeeep","https://www.buymeacoffee.com/lukeeep"],"categories":["Macros"],"sub_categories":[],"readme":"\u003cp\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Swift-5.9-f05318.svg\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/iOS-\u003e= 13.0-blue.svg\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/macOS-\u003e= 11.0-blue.svg\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/watchOS-\u003e= 6.0-blue.svg\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/tvOS-\u003e= 13.0-blue.svg\" /\u003e\n  \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/lukepistrol/SFSymbolsMacro\"\u003e\n  \u003ca href=\"https://twitter.com/lukeeep_\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Twitter-@lukeeep_-1e9bf0.svg?style=flat\" alt=\"Twitter: @lukeeep_\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# SFSymbolsMacro\n\nThis Swift Macro provides an easy way to make the use of SF Symbols in Swift more or less *\"type-safe\"*.\n\n## Installation\n\n### Xcode\n\n1. Click File \u003e Add Package Dependencies\n2. Paste the following link into the search field on the upper-right:\n   ```\n   https://github.com/lukepistrol/SFSymbolsMacro.git\n   ```\n\n### Swift Package Manager\n\nIn `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/lukepistrol/SFSymbolsMacro.git\", from: \"0.1.0\")\n]\n```\n\nAnd then add the dependency to your targets.\n\n## Usage\n\nSimply create an `enum` which will hold all the SF Symbols for your project:\n\n```swift\nenum Symbols: String {\n    case circle\n    case circleFill = \"circle.fill\"\n    case shareIcon = \"square.and.arrow.up\"\n    case globe\n}\n```\n\nThen simply import `SFSymbolsMacro` and add the `@SFSymbol` macro annotation to the enum:\n\n```swift\nimport SFSymbolsMacro\nimport SwiftUI\n\n@SFSymbol\nenum Symbols: String { ... }\n```\n\nThe macro will then validate each `case` and the expanded macro will look something like this:\n\n```swift\nenum Symbols: String {\n    case circle\n    case circleFill = \"circle.fill\"\n    case shareIcon = \"square.and.arrow.up\"\n    case globe\n\n    var image: Image {\n        Image(systemName: self.rawValue)\n    }\n    var name: String {\n        self.rawValue\n    }\n    #if canImport(UIKit)\n    func uiImage(configuration: UIImage.Configuration? = nil) -\u003e UIImage {\n        UIImage(systemName: self.rawValue, withConfiguration: configuration)!\n    }\n    #else\n    func nsImage(accessibilityDescription: String? = nil) -\u003e NSImage {\n        return NSImage(systemSymbolName: self.rawValue, accessibilityDescription: accessibilityDescription)!\n    }\n    #endif\n    func callAsFunction() -\u003e String {\n        return self.rawValue\n    }\n}\n```\n\nIn your code you can then call a symbol:\n\n```swift\nvar body: some View {\n    VStack {\n        Symbols.circleFill.image\n        Label(\"Globe\", systemImage: Symbols.globe.name)\n        // the above can also be written as\n        Label(\"Globe\", systemImage: Symbols.globe())\n    }\n}\n```\n\nIn case the provided raw value is not a valid SF Symbol, Xcode will show a compile error at the `enum-case` in question:\n\n![explicit raw value](https://github.com/lukepistrol/SFSymbolsMacro/assets/9460130/36713049-6b14-4fc4-8a07-df86837e4704)\n\n![inferred raw value](https://github.com/lukepistrol/SFSymbolsMacro/assets/9460130/9db30861-4b98-4e31-9c41-0b5e0a553293)\n\n\n## Contribution\n\nIf you have any ideas on how to take this further I'm happy to discuss things in an issue.\n\n-----\n\n\u003ca href=\"https://www.buymeacoffee.com/lukeeep\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukepistrol%2FSFSymbolsMacro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukepistrol%2FSFSymbolsMacro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukepistrol%2FSFSymbolsMacro/lists"}