Files
2026-01-31 10:41:02 +01:00

59 lines
1.3 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// SFSymbol.swift
// GradientLoadingBarExample
//
// Created by Felix Mau on 10.01.26.
// Copyright © 2026 Felix Mau. All rights reserved.
//
import SwiftUI
import UIKit
/// SF Symbols used by the example application.
///
/// Using an enum avoids hard-coded string literals and improves discoverability, autocompletion and compile-time safety.
/// The raw value of each case corresponds to the SF Symbols system name.
enum SFSymbol: String {
case eye
case eyeSlash = "eye.slash"
case iPhoneGen2 = "iphone.gen2"
case iPhoneGen3 = "iphone.gen3"
case squareStack = "square.stack"
case swift
}
// MARK: - Helper
extension Image {
/// Creates a SwiftUI `Image` from an `SFSymbol`.
///
/// ### Usage
///
/// ```swift
/// Image(sfSymbol: .house)
/// ```
///
/// - Parameter sfSymbol: The SF Symbol to display.
init(sfSymbol: SFSymbol) {
self.init(systemName: sfSymbol.rawValue)
}
}
extension UIImage {
/// Creates a `UIImage` from an `SFSymbol`.
///
/// ### Usage
///
/// ```swift
/// let image = UIImage(sfSymbol: .plus)
/// ```
///
/// - Parameter sfSymbol: The SF Symbol to display.
///
/// - Returns: A system image, or `nil` if the symbol name is invalid or
/// unavailable on the current OS version.
convenience init?(sfSymbol: SFSymbol) {
self.init(systemName: sfSymbol.rawValue)
}
}