Skip to content

πŸ’Ÿ SFSymbols gives you a ready-to-use symbol picker for SwiftUI and an async API for reading the system SF Symbols catalog.

License

Notifications You must be signed in to change notification settings

simonbs/SFSymbols

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SFSymbols

SFSymbols provides an SF Symbol picker and a simple API for accessing the SF Symbols catalog.

Use it to let users choose symbols in-app or to build your own symbol browser.


SwiftLint Build Build Example Project



πŸš€ Getting Started

This section walks through adding SFSymbols and using the three primary APIs.

Add the SFSymbols Swift Package

Add SFSymbols to your Xcode project or Swift package.

let package = Package(
    dependencies: [
        .package(url: "https://github.com/simonbs/SFSymbols.git", from: "1.0.0")
    ]
)

Use SFSymbolPicker

SFSymbolPicker is a SwiftUI view that presents a labeled row with a button showing the current symbol.

import SFSymbols
import SwiftUI

struct ContentView: View {
    @State private var selectedSymbol = "tortoise"

    var body: some View {
        Form {
            SFSymbolPicker("Symbol", selection: $selectedSymbol)
        }
    }
}

SFSymbolPicker accepts both optional and non-optional bindings. Optional bindings let you clear the selection.

Present the Picker With .sfSymbolPicker(...)

Use the view modifier when you want full control over the button or the presentation trigger.

import SFSymbols
import SwiftUI

struct ContentView: View {
    @State private var isPresented = false
    @State private var selectedSymbol: String?

    var body: some View {
        Button {
            isPresented = true
        } label: {
            Label("Pick a Symbol", systemImage: selectedSymbol ?? "questionmark")
        }
        .sfSymbolPicker(isPresented: $isPresented, selection: $selectedSymbol)
    }
}

.sfSymbolPicker can be attached to any view, including images, list rows, or custom buttons.

Load and Browse Symbols With SFSymbols

SFSymbols loads the system catalog asynchronously. Use it to build custom filters, category views, or search.

import SFSymbols
import SwiftUI

struct SymbolBrowser: View {
    @State private var symbols: SFSymbols?

    var body: some View {
        List {
            if let symbols {
                ForEach(symbols.categories) { category in
                    Section(category.key) {
                        ForEach(category.symbols) { symbol in
                            Label(symbol.name, systemImage: symbol.name)
                        }
                    }
                }
            }
        }
        .task {
            symbols = try? await SFSymbols()
        }
    }
}

SFSymbols exposes the full list of symbols and their categories.

let symbols = try await SFSymbols()
let allSymbols = symbols.symbols
let categories = symbols.categories

Each SFSymbol includes its name, searchTerms, and categories, so you can build your own search and filtering UI.

πŸ“± Example Project

Open the example app in Example/Example.xcodeproj to see SFSymbolPicker in a simple form.

About

πŸ’Ÿ SFSymbols gives you a ready-to-use symbol picker for SwiftUI and an async API for reading the system SF Symbols catalog.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages