Skip to content
Safely access Apple's SF Symbols using static typing
Branch: stable
Clone or download
Latest commit 8d933a6 Jun 22, 2019

README.md

Build Status Swift: 5.1 Version: 0.3.1 Platforms: iOS License: MIT
SwiftPM: Compatible Accio: supported Carthage: compatible

MotivationInstallationUsageContributingLicenseIssuesPull Requests

Motivation

At WWDC 2019, Apple announced a new library of icons that come included with iOS 13. To browse them, there's even a dedicated Mac app called SF Symbols. However, developers still have to copy the name of an icon 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 what this framework does!

Installation

SFSafeSymbols can be installed via Swift Package Manager, Accio, Carthage or CocoaPods:

Swift Package Manager

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

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

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

Accio

Do the same configurations as for SwiftPM, then run accio update instead of swift package update.

Carthage

Add the following entry to your Cartfile:

github "piknotech/SFSafeSymbols" ~> 0.3

Then run carthage update.

CocoaPods

CocoaPods support is currently on hold as there are some compatibility issues. However, we are working eagerly to readd it as soon as possible. This issue will track progress on the matter.

Usage

All the system icons are accessible via the SFSymbol enum. They are named similar to Apple's naming, 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

You can now either create the corresponding UIImage by initializing it using the SFSymbol:

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

Or by calling a function on your SFSymbol instance:

SFSymbol.cCircle.toImage
SFSymbol.eCircleFill.toImage(withConfiguration: /* Some UIImage.Configuration */)
SFSymbol._11CircleFill.toImage(compatibleWith: /* Some UITraitCollection */)

You can also create a SwiftUI.Image by using new initializers that take a SFSymbol reference:

Image(systemSymbol: .cCircle)

All symbols are tested so you can be sure your code won't crash because an image couldn't be found!

Contributing

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

License

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

You can’t perform that action at this time.