Introducing SFSymbolsFinder
Compact Tools for SFSymbols
Recently I got stumbled with a boring way to create an icon from SF Symbols. As you know that Apple introduces SF Symbols for a developer to reuse in their own application if needed. SF Symbols is a set of over 1,500 symbols that you can use in your app. Why SFSymbols are great for indie developers?
- It is free
- Optical alignment with text for all weights and sizes
- Support multicolor
- Support localization for RTL languages such as Arabic, Devanagari, and Hebrew
Normally we will do something like this for using the SFSymbols
UIImage(systemName: "gear") --> UIKit
// or
Image(systemName: "gear") --> SwiftUI
But it is quite burdensome if I need to do it for a longer string such as line.horizontal.3.decreasesymbol
. Since I need to apply some of the icons in my own pet project, I decided to make a new Swift Package Manager for this one.
SFSymbolsFinder
SFSymbolsFinder will act as convenient enum that converts available symbols to either Image or a String. This library will support more than 15 available categories listed in the SF Symbols app from Apple. Right now it is mostly supported symbols from v1.1, however gradually I will add more support for v2.2 How to use these symbols? It is pretty easy. Considering we want to use SwiftUI in our project, we can either use an image or string of system name like below
1import SwiftUI
2import SFSymbolsFinder
3
4// Use Shape Circle symbols
5
6Shape.rectangle.image // return Image(systemName: "rectangle")
7
8Shape.rectangle // return a View
9
10Image(systemName: Shape.rectangle.systemName) // return "rectangle"
11
12// Use All for every SF Symbols
13
14All.rectangle.image // return Image(systemName: "rectangle")
15
16All.rectangle // return a View
You can either use one of the options as I described above The benefit of using SFSymbolsFinder:
- You don’t need to type a literal string every time
- You have autocompleted for each category when typing in the code
- You can have one single source of truth where the Image is coming from
- All icon name and enum is matched with the one provided with apple
Finally, that’s all my introduction to my latest SPM package. Find out more about the official documentation here: https://github.com/abadikaka/SFSymbolsFinder All contributions and supports are greatly appreciated!