Swiftpack.co - jollyjinx/SFSymbolEnum as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jollyjinx.
jollyjinx/SFSymbolEnum 2.3.0
A swift package to have SF Symbols available as enum instead of verbatim strings.
⭐️ 30
🕓 46 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/jollyjinx/SFSymbolEnum.git", from: "2.3.0")

SFSymbolEnum

A swift package to have SF Symbols available as enum instead of verbatim strings.

You can write now:

Image(systemImage:.person)
Label("Text",systemImage:.zlRectangleRoundedtopFill)

Or to see a list of all available symbols

struct SwiftUIView: View {
    var body: some View {
        VStack {
            List(SFSymbol.allCases,id:\.name) { symbol in
                Label(symbol.name,systemImage:symbol)
            }
        }
    }
}

Advantages

  • Compiler error when you mistype a SFSymbol name
  • Autocompletion and suggestion for all SFSymbols:
  • Images are available depending on os and version like this:

Installation

     import SFSymbolEnum

Usage

functions that are using the systemImage argument can be used as before, but instead with the dot notation. Symbol names translate to enums by replacing dots notation to camelcase and prefixing starting numbers with number.

Examples:

    Image(systemName:"arrow.down.left.circle.fill")
    Image(systemName:"0.circle")
    Image(systemName:"arrow.2.circlepath.circle")

becomes to:

    Image(systemName:.arrowDownLeftCircleFill)    
    Image(systemName:.number0Circle)    
    Image(systemName:.arrow2CirclepathCircle)    

How it's done

The code itself has been created with the name_availablity.plist inside the SF Symbols application and looks like this

public enum SFSymbol:String  // this enum will be generated
{
    @available(iOS 13.0,macOS 10.15,tvOS 13.0,watchOS 6.0,*) case number0Circle = "0.circle"
    @available(iOS 13.0,macOS 10.15,tvOS 13.0,watchOS 6.0,*) case number0CircleFill = "0.circle.fill"
...
}

extension SFSymbol:CaseIterable
{
    public static var allCases:[SFSymbol] {
                var allCases:[SFSymbol] = []
        if #available(iOS 13.0,macOS 10.15,tvOS 13.0,watchOS 6.0,*){ allCases.append(SFSymbol.number0Circle) }
        if #available(iOS 13.0,macOS 10.15,tvOS 13.0,watchOS 6.0,*){ allCases.append(SFSymbol.number0CircleFill) }
...
    return allCases	
    }
}

GitHub

link
Stars: 30
Last commit: 46 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

SFSymbols 4.0 update
46 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics