Home

Awesome

<p align="center"> <img src="https://raw.githubusercontent.com/SFSafeSymbols/SFSafeSymbols/stable/Logo.png" width=600> </p> <p align="center"> <a href="https://app.bitrise.io/app/f9e56287b4a18852#/builds"> <img src="https://app.bitrise.io/app/f9e56287b4a18852/status.svg?token=PwV0AjHnLm32ht_GGzff3w&branch=stable" alt="Build Status"> </a> <a href="#"> <img src="https://img.shields.io/badge/swift-5-FFAC45.svg" alt="Swift: 5"> </a> <a href="https://github.com/SFSafeSymbols/SFSafeSymbols/releases"> <img src="https://img.shields.io/badge/version-5.3-blue.svg" alt="Version: 5.3"> </a> <a href="#"> <img src="https://img.shields.io/badge/Platforms-iOS%20|%20tvOS%20|%20watchOS%20|%20macOS-FF69B4.svg" alt="Platforms: iOS – tvOS – watchOS – macOS"> </a> <a href="https://github.com/SFSafeSymbols/SFSafeSymbols/blob/stable/LICENSE"> <img src="https://img.shields.io/badge/license-MIT-lightgrey.svg" alt="License: MIT"> </a> <br /> <a href="https://github.com/apple/swift-package-manager"> <img src="https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg" alt="SwiftPM: Compatible"> </a> <a href="https://github.com/Carthage/Carthage"> <img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage: Compatible"> </a> <a href="https://cocoapods.org/pods/SFSafeSymbols"> <img src="https://img.shields.io/badge/CocoaPods-compatible-4BC51D.svg?style=flat" alt="CocoaPods: Compatible"> </a> </p> <p align="center"> <a href="#idea--features">Idea & Features</a> • <a href="#supported-versions">Supported Versions</a> • <a href="#installation">Installation</a> • <a href="#usage">Usage</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a> • <a href="https://github.com/SFSafeSymbols/SFSafeSymbols/issues">Issues</a> • <a href="https://github.com/SFSafeSymbols/SFSafeSymbols/pulls">Pull Requests</a> </p>

Idea & Features

At WWDC 2019, Apple announced a new library of icons that came included with that year's new operating system versions. To browse them, there's a dedicated Mac app called SF Symbols. However, developers still have to copy the name of a symbol and reference it unsafely, resulting in code like this:

UIImage(systemName: "circle.fill")

It didn't take long until first ideas came up to make these icons accessible in a safe way using a framework. And this is just the basic idea behind SFSafeSymbols!

Furthermore, with SFSafeSymbols...

Supported Versions

The following SF Symbols versions are currently supported:

SF Symbols VersioniOS VersionmacOS VersiontvOS VersionwatchOS Version
1.0 13.011.013.06.0
1.1 13.111.013.06.1
2.0 14.011.014.07.0
2.1 14.211.014.27.1
2.2 14.511.314.57.4
3.0 15.012.015.08.0
3.1 15.112.015.18.1
3.2 15.212.115.28.3
3.3 15.412.315.48.5
4.0 16.013.016.09.0
4.1 16.113.016.19.1
4.2 16.413.316.49.4
5.0 17.014.017.010.0
5.1 17.114.117.110.1
5.2 17.214.217.210.2
5.3 17.414.417.410.4

Installation

SFSafeSymbols can be installed via the Swift Package Manager (recommended), Carthage or CocoaPods.

Supported platforms are iOS (11.0+), macOS (10.13+), tvOS (11.0+) and watchOS (4.0+), although the actual functionality is of course only accessible starting with iOS 13.0, macOS 11.0, tvOS 13.0 and watchOS 6.0.

Swift Package Manager (Xcode-integrated)

To integrate SFSafeSymbols using the Xcode-built-in SPM, choose FileSwift PackagesAdd Package Dependency. Enter the following url: https://github.com/SFSafeSymbols/SFSafeSymbols and click Next. When asked about the version, leave the preselection and click Next. In the following step, select SFSafeSymbols as the package product and click Finish.

Swift Package Manager (standalone)

To integrate using the standalone version of Apple's Swift Package Manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/SFSafeSymbols/SFSafeSymbols.git", .upToNextMajor(from: "5.3"))

After specifying "SFSafeSymbols" as a dependency of the target in which you want to use it, run swift package update.

Carthage

Add the following entry to your Cartfile:

github "SFSafeSymbols/SFSafeSymbols" ~> 5.3

Then run carthage update.

CocoaPods

Add the following entry to your Podfile:

pod 'SFSafeSymbols', '~> 5.3'

Then run pod install.

Usage

All the system symbols are accessible via the SFSymbol type. They are named similar to Apple's names, but use a lower camel case style and prefix names with leading numbers with a _ character:

c.circle        ~> SFSymbol.cCircle
e.circle.fill   ~> SFSymbol.eCircleFill
11.circle.fill  ~> SFSymbol._11CircleFill

A SF Symbol UIImage can now be initialized using the SFSymbol type. This image is already unwrapped, so you get a UIImage instead of a UIImage?:

UIImage(systemSymbol: .cCircle)
UIImage(systemSymbol: SFSymbol.eCircleFill)
UIImage(systemSymbol: ._11CircleFill, withConfiguration: /* Some UIImage.Configuration */)

A SF Symbol SwiftUI.Image can also be initialized using the SFSymbol type:

Image(systemSymbol: .cCircle)
Image(systemSymbol: SFSymbol.eCircleFill)

There are also SwiftUI.Label initializers:

Label("MyText", systemSymbol: .cCircle)
Label(LocalizedStringKey("my.text"), systemSymbol: SFSymbol.eCircleFill)

... and an initializer for SwiftUI.Button:

Button("MyText", systemSymbol: .cCircle){}
Button(LocalizedStringKey("my.text"), systemSymbol: SFSymbol.eCircleFill){}
Button("MyText", systemSymbol: .cCircle, role: .cancel){}
Button(LocalizedStringKey("my.text"), systemSymbol: SFSymbol.eCircleFill, role: .cancel){}
Button("MyText", systemSymbol: .cCircle, role: .cancel, intent: intent)
Button(LocalizedStringKey("my.text"), systemSymbol: SFSymbol.eCircleFill, intent: intent)

... and an initializer for UIApplicationShortcutItem:

UIApplicationShortcutIcon(systemSymbol: .cCircle)
UIApplicationShortcutIcon(systemSymbol: SFSymbol.eCircleFill)

... and finally also an initializer for AppKit's NSImage:

NSImage(systemSymbol: .cCircle)
NSImage(systemSymbol: SFSymbol.eCircleFill, accessibilityDescription: "some.description")

Localization

SF Symbols can come with multiple different localizations. SFSafeSymbols exposes localization the following way:

Attention: Serializing and deserializing SFSymbols currently makes them lose their explicit static localization information. Dynamic localization information will still be retained.

Swiftlint

You may want to leverage SwiftLint to ensure that SFSafeSymbols is used when appropriate. In your .swiftlint.yml file, you can add a custom rule like this:

custom_rules:
  sf_safe_symbol:
    name: "Safe SFSymbol"
    message: "Use `SFSafeSymbols` via `systemSymbol` parameters for type safety."
    regex: "(Image\\(systemName:)|(NSImage\\(symbolName:)|(Label[^,]+?,\\s*systemImage:)|(UIApplicationShortcutIcon\\(systemImageName:)"
    severity: warning

Contributing

Contributions are very much welcome! See CONTRIBUTING.md for more information.

License

This library is released under the MIT License. See LICENSE for details.