/safe-san-francisco

Typesafe access to SFSymbols on all Apple platforms

Primary LanguageSwift

Safe San Francisco

Typesafe access to SFSymbols on all Apple platforms.

Contents

The package provides a library for structural access to SFSymbols. The syntax is built in such a way that you should be able to copy the symbol name from the SF Symbols app and paste it following a SF namespace:

// As UIImage or NSImage
let personCropCircle = SF.person.crop.circle.image()

// As SwiftUI Image
let personCropCircleFill = SF.person.crop.circle.fill.swiftUIImage()

// Store reference to SFSymbol 
let arrowUp = SF.arrow.up.self

Availability

All symbols are tagged with the version in which they became available. This eliminates crashes or missing icons on older versions by checking availability at compile-time:

@available(iOS 16.0, *)
static let sailboat = SF.sailboat.self

Special names

As variable names cannot start with a number, numbers are preceded with an underscore or a x:

let oneSquare = SF.x1.square.self
let oneSquare = SF._1.square.self

The name image is reserved by this framework, and so needs to be preceded by either an underscore or x_:

let docTextImage = SF.doc.text.x_image.self

let docTextImageFill = SF.doc.text.x_image.fill.self

Reserved names in Swift—like switch—are escaped and can be used without any problems:

let switch2 = SF.switch.x2.self

Using Safe San Francisco in your project

To use this package in a SwiftPM project, you need to set it up as a package dependency:

// swift-tools-version:5.7
import PackageDescription

let package = Package(
  name: "MyPackage",
  dependencies: [
    .package(
      url: "https://github.com/shortcut/safe-san-francisco.git", 
      .upToNextMinor(from: "1.0.0") // or `.upToNextMajor
    )
  ],
  targets: [
    .target(
      name: "MyTarget",
      dependencies: [
        .product(name: "SafeSanFrancisco", package: "SafeSanFrancisco")
      ]
    )
  ]
)

Contributing to Safe San Francisco

Contributions are welcome and encouraged. The code for arranging all symbols are generated by the SFSymbolsHunter tool in this repo. If you discover a symbol is missing, or has wrong information—like availability—do not hesitate to open an issue.

If you discover optimization routes, like saving space, memory or reducing build time. Your sharing of knowledge is greatly appreciated.