๐ Language / ่ช่จ้ธๆ
Simplifying SF Symbols Enumeration Generation with Swift!
A Swift-based command-line utility that generates type-safe Swift enumerations for SF Symbols with proper availability annotations, built with clean architecture principles.
- ๐ฏ Type-Safe Generation: Creates Swift enumerations with compile-time safety
- ๐ฑ Availability Annotations: Automatic
@available
attributes for proper platform support - ๐ Dual Version Support: Works with both stable and beta SF Symbols versions
- ๐๏ธ Clean Architecture: Well-structured codebase following SOLID principles
- โก Performance Optimized: Fast symbol processing and code generation
- ๐ ๏ธ Keyword Handling: Proper handling of Swift reserved keywords
- ๐ Documentation: Comprehensive inline documentation and comments
- macOS: 14.0 or later
- Xcode: 15.0 or later
- Swift: 5.8 or later
- SF Symbols App: Version 5.0 or later (stable) / Version 7.0 or later (beta)
This project follows Clean Architecture principles with a clear separation of concerns:
Sources/
โโโ Application/ # Application Layer
โ โโโ Commands/ # CLI command implementations
โ โโโ SFSymbolsGenerator.swift
โโโ Domain/ # Domain Layer
โ โโโ Models/ # Domain models and extensions
โ โโโ Services/ # Core business logic services
โโโ Infrastructure/ # Infrastructure Layer
โ โโโ FileSystem/ # File operations
โ โโโ Errors/ # Error handling
โโโ Foundation/ # Foundation Layer
โโโ Types/ # Type aliases and basic types
- Maintainability: Clear separation makes the code easy to understand and modify
- Testability: Each layer can be independently tested
- Scalability: Easy to add new features without affecting existing code
- Reusability: Components can be reused across different contexts
brew tap leoho0722/tap
brew install sf-symbols-generator
- Download the latest binary from GitHub Releases
- Extract and place the binary in your desired location
- Make it executable:
chmod +x sf-symbols-generator
git clone https://github.com/leoho0722/SFSymbolsGenerator.git
cd SFSymbolsGenerator
swift build -c release
# Binary will be at .build/release/sf-symbols-generator
sf-symbols-generator generate <filepath> [--name <name>] [--enum-name <enum-name>] [--use-beta]
sf-symbols-generator version
# Basic usage
sf-symbols-generator generate /path/to/output
# With custom filename
sf-symbols-generator generate /path/to/output --name CustomSymbols
# Using beta version
sf-symbols-generator generate /path/to/output --use-beta
# Complete example
sf-symbols-generator generate ~/Desktop --name MySymbols --use-beta
Option | Description | Default | Required |
---|---|---|---|
filepath |
Directory where the Swift file will be generated | - | โ |
--name |
Specify filename of output | SFSymbols+Enum |
โ |
--enum-name |
Specify enum name of output | SFSymbols |
โ |
--use-beta |
Whether use beta version of SF Symbols or not | false |
โ |
The tool generates a Swift enumeration file with the following structure:
// SFSymbols.swift
// Generated by SFSymbolsGenerator
// Do not edit this file manually.
import Foundation
public enum SFSymbols: String, CaseIterable {
/// SF Symbols's name๏ผarrow.left
@available(iOS 13.0, macOS 10.15, *)
case arrowLeft = "arrow.left"
/// SF Symbols's name๏ผstar.fill
@available(iOS 14.0, macOS 11.0, *)
case starFill = "star.fill"
public static var allCases: [SFSymbols] {
var allCases: [SFSymbols] = []
if #available(iOS 13.0, macOS 10.15, *) {
allCases.append(.arrowLeft)
}
if #available(iOS 14.0, macOS 11.0, *) {
allCases.append(.starFill)
}
return allCases
}
}
swift build
swift test
- Application Layer: Contains the main CLI interface and command handling
- Domain Layer: Core business logic for symbol processing and code generation
- Infrastructure Layer: File I/O operations and error handling infrastructure
- Foundation Layer: Basic types, aliases, and utility definitions
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Follow Swift coding conventions
- Maintain clean architecture principles
- Add tests for new functionality
- Update documentation as needed
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Use the generated enumeration
let imageView = UIImageView()
imageView.image = UIImage(systemName: SFSymbols.starFill.rawValue)
// Check availability
if SFSymbols.allCases.contains(.arrowLeft) {
print("Arrow left symbol is available")
}
}
}
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: SFSymbols.starFill.rawValue)
.font(.largeTitle)
Text("Available symbols: \\(SFSymbols.allCases.count)")
}
}
}
The tool provides detailed error messages for various scenarios:
- SF Symbols application not installed
- File permission issues
- Data format errors
- Code generation failures
The tool automatically handles:
- Dot notation to camelCase conversion (
arrow.left
โarrowLeft
) - Swift keyword handling (
return
โ`return`
) - Numbers at the beginning (
1.circle
โ_1Circle
)
Automatically generates based on SF Symbols release timeline:
- iOS 13.0+: Symbols released in 2019
- iOS 14.0+: Symbols released in 2020
- iOS 15.0+: Symbols released in 2021
- And so on...
Q: SF Symbols application not found
A: Make sure you have downloaded and installed the SF Symbols app from Apple Developer website.
Q: Generated file is empty
A: Check that your SF Symbols app version is correct and that symbol data is available.
Q: Permission denied
A: Ensure the output directory has write permissions, or run the command with sudo
.
If you encounter issues, please create a GitHub issue with:
- Error message
- Command executed
- System environment (macOS version, SF Symbols version)
- Expected vs actual behavior
This project is licensed under the MIT License - see the LICENSE file for details.
- jollyjinx/SFSymbolEnum - Original inspiration
- Apple Inc. - For creating SF Symbols
For more detailed documentation, please check:
- ็น้ซไธญๆ่ชชๆๆไปถ
- Source code documentation (inline comments)
Made with โค๏ธ by Leo Ho