Swiftpack.co - Package - piknotech/SFSafeSymbols

Supported Versions

SFSafeSymbols supports multiple SF Symbols versions at the same time by utilizing the @availability flag. The following versions are currently supported:

  • SF Symbols 2.1 (@available(iOS 14.2, macOS 11.0, tvOS 14.2, watchOS 7.1, *))
  • SF Symbols 2.0 (@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *))
  • SF Symbols 1.0 (@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *))

Motivation

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 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 SFSafeSymbols does!

Installation

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

Supported platforms are iOS (11.0+), tvOS (11.0+), watchOS (6.0+) and macOS (10.13+), although the actual functionality is of course only accessible starting with iOS 13.0, tvOS 13.0, watchOS 6.0 and macOS 11.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/piknotech/SFSafeSymbols. From there on, just click Next multiple times and choose Finish in the end. That's it.

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/piknotech/SFSafeSymbols.git", .upToNextMajor(from: "2.1.0"))

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 "piknotech/SFSafeSymbols" ~> 2.1.0

Then run carthage update.

CocoaPods

Add the following entry to your Podfile:

pod 'SFSafeSymbols', '~> 2.1.0'

Then run pod install.

Usage

All the system icons are accessible via the SFSymbol enum. 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 enum. 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 enum:

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 interfaces for UIButton:

let button = UIButton.systemButton(with: .cCircle, target: self, selector: #selector(testMethod))
button.setImage(.eCircleFill, for: .normal)

... 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")

Testing

All symbols are tested via a CI (on the latest iOS & tvOS versions), 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 for details.

Github

link
Stars: 571

Dependencies

Used By

Total: 0

Releases

Version 2.1.0 -

Added

Version 2.0.2 -

Fixed

Version 2.0.1 -

Fixed

  • Fix public availability of SwiftUI Label initializers (By Seb Jachec)

Version 2.0.0 -

This release adds support for the 2020 v2 SF Symbols – thanks to @Robuske, @hstdt and @sebj who contributed to this release! 🚀

Here's the full changelog:

Added

Changed

  • Add macOS support for SwiftUI Image initializer (By Seb Jachec)

Version 1.2.0 -

Added

  • Add a UIButton extension with systemButton(with:, target:, action:) initializer and setImage(_:, for:) (By Antonino Musolino)

Changed

  • None

Fixed

  • None

Version 1.1.1 -

Added

  • Add UIApplicationShortcutIcon initializer (By Seb Jachec)

Changed

  • None

Fixed

  • None

Version 1.1.0 -

Added

Changed

  • None

Fixed

  • None

Version 1.0.2 -

Added

  • None

Changed

  • None

Fixed

Version 1.0.1 -

Added

  • None

Changed

  • None

Fixed

  • Fix macOS compilation when installed via Carthage (By Chris Zielinski)
  • Fix compatibility with older iOS versions when installed via CocoaPods (By @jstarfruits)

Version 1.0.0 -

Added

  • None

Changed

  • Update to symbols that are actually available in the final iOS 13, tvOS 13 and watchOS 6 releases (By Frederick Pietschmann)

Fixed

  • None

Version 0.4.0 -

Added

  • None

Changed

Fixed

Version 0.3.1 -

Added

  • Extended support for SwiftUI.Image initializer to macOS, tvOS and watchOS platforms (By Eric Lewis)

Changed

Version 0.3.0 -

Added

Version 0.2.0 -

Added

Changed

Fixed

  • Fix tests for iOS 12 and below; instead of not compiling, the tests simply fail (By David Knothe)

Version 0.1.1 -

Make library static

Version 0.1.0 -

Initial release.