### Run Example Application Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Navigate to the example application directory and open the Xcode project to run the demonstration. ```bash cd Example/PhosphorSwiftExample open PhosphorSwiftExample.xcodeproj ``` -------------------------------- ### Color with Shadow Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Shows how to apply a color to an icon and then add a shadow effect to it. ```swift Ph.star.fill .frame(width: 64, height: 64) .color(.yellow) .shadow(color: Color.yellow.opacity(0.5), radius: 8) ``` -------------------------------- ### Color with Overlay Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Demonstrates applying a color to an icon and then adding an overlay to it, such as a border. ```swift Ph.heart.fill .frame(width: 80, height: 80) .color(.red) .overlay( Circle() .stroke(Color.red, lineWidth: 2) ) ``` -------------------------------- ### Color Options Examples Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Provides examples of using various SwiftUI `Color` options with the `color(_:)` modifier, including system colors, custom colors, and colors with opacity. ```swift // System colors .color(.red) .color(.blue) .color(.green) .color(.gray) .color(.accentColor) .color(.primary) .color(.secondary) // Custom colors .color(Color(red: 0.5, green: 0.2, blue: 0.8)) // Color with opacity .color(.blue.opacity(0.5)) ``` -------------------------------- ### Example Test Case Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md This example test demonstrates how to use the `resizable` and `color` modifiers on an icon and prints the resulting image to the debug console. ```swift func testExample() throws { let a = Ph.addressBook.regular .resizable() .color(.blue) .aspectRatio(contentMode: .fit) debugPrint(a) } ``` -------------------------------- ### Icon Grid with Colors Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Demonstrates creating a grid of icons, each colored with a different color from a predefined array. ```swift struct ColoredIconGrid: View { let colors: [Color] = [.red, .orange, .yellow, .green, .blue, .purple] var body: some View { LazyVGrid(columns: [GridItem(.adaptive(minimum: 60))]) { ForEach(Array(Ph.allCases.enumerated()), id: ".offset") { index, icon in icon.regular .frame(width: 60, height: 60) .color(colors[index % colors.count]) } } } ``` -------------------------------- ### Dynamic Color Selection Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Shows how to use a `ColorPicker` to dynamically change the color of a Phosphor icon. ```swift struct DynamicColorIcon: View { @State private var iconColor = Color.blue var body: some View { VStack { ColorPicker("Icon Color", selection: $iconColor) Ph.star.fill .frame(width: 80, height: 80) .color(iconColor) } ``` -------------------------------- ### Toggle Between Weights Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Example showing how to switch icon weights based on application state, such as a button tap. ```APIDOC ### Toggle Between Weights Switch weights based on application state: ```swift struct InteractiveIcon: View { @State private var isActive = false var body: some View { Button { isActive.toggle() } label: { Ph.star .weight(isActive ? .fill : .regular) .frame(width: 44, height: 44) .foregroundColor(isActive ? .yellow : .gray) } } } ``` ``` -------------------------------- ### SwiftUI Quick Start with Phosphor Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Demonstrates how to use Phosphor icons in a SwiftUI view, showing static and dynamic weight usage with frame and color modifiers. ```swift import SwiftUI import PhosphorSwift struct ContentView: View { var body: some View { VStack { // Use an icon with a specific weight Ph.heart.fill .frame(width: 64, height: 64) .color(.red) // Use a dynamic weight Ph.star.weight(.bold) .frame(width: 64, height: 64) .color(.yellow) } } } ``` -------------------------------- ### Weight Selection UI Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Example of building a custom weight picker UI that allows users to select and preview different icon weights. ```APIDOC ### Weight Selection UI Build a weight picker for icon customization: ```swift struct WeightPicker: View { @State private var selectedWeight: Ph.IconWeight = .regular var body: some View { VStack { HStack(spacing: 12) { ForEach(Ph.IconWeight.allCases) { weight in Button { selectedWeight = weight } label: { Text(weight.rawValue.capitalized) .padding(8) .background(selectedWeight == weight ? Color.blue : Color.gray.opacity(0.2)) .cornerRadius(4) } } } Ph.gear .weight(selectedWeight) .frame(width: 80, height: 80) } } } ``` ``` -------------------------------- ### Colored Icon Set Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Displays a horizontal stack of icons, each with a different color applied. ```swift HStack(spacing: 16) { Ph.checkCircle.fill .color(.green) Ph.warning.fill .color(.orange) Ph.xCircle.fill .color(.red) } .frame(height: 32) ``` -------------------------------- ### Basic Icon Coloring Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Demonstrates how to apply a basic red color to a Phosphor icon using the `color(_:)` modifier. ```swift import SwiftUI import PhosphorSwift struct ColoredIcon: View { var body: some View { Ph.heart.regular .frame(width: 64, height: 64) .color(.red) } ``` -------------------------------- ### Dynamic Access (Runtime) Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Example demonstrating how to use the `weight(_:)` method to apply an icon weight determined at runtime, often used with UI elements like Pickers. ```APIDOC ### Dynamic Access (Runtime) Use the `weight(_:)` method on any icon to apply a weight determined at runtime: ```swift import SwiftUI import PhosphorSwift struct IconViewer: View { @State private var selectedWeight: Ph.IconWeight = .regular var body: some View { VStack { Picker("Weight", selection: $selectedWeight) { ForEach(Ph.IconWeight.allCases) { weight in Text(weight.rawValue).tag(weight) } } Ph.heart .weight(selectedWeight) .frame(width: 64, height: 64) .color(.red) } } } ``` ``` -------------------------------- ### Icon Grid Layout Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Provides an example of displaying all available Phosphor icons in a responsive grid using `LazyVGrid`. ```swift LazyVGrid(columns: [GridItem(.adaptive(minimum: 50))]) { ForEach(Ph.allCases) { icon in icon.regular .frame(width: 50, height: 50) } } ``` -------------------------------- ### Ph Icon Access Examples Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/types.md Shows how to access individual icons and their weight variants, including static and dynamic access methods. ```swift // Static weight access Ph.heart.regular Ph.gear.bold // Dynamic weight access Ph.house.weight(.fill) // Enumeration ForEach(Ph.allCases) { icon.regular } ``` -------------------------------- ### Dynamic Icon Access Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Shows how to access an icon dynamically using its name and a specified weight. This allows for more flexible icon rendering based on variables. ```swift Ph..weight(Ph.IconWeight) ``` -------------------------------- ### Static Access (Compile-Time) Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Example of accessing icon weights directly on an icon when the weight is known at compile time. ```APIDOC ## Usage ### Static Access (Compile-Time) For weight known at compile time, access directly on icon: ```swift Ph.house.regular Ph.heart.bold Ph.star.fill Ph.gear.duotone ``` ``` -------------------------------- ### Basic Icon Usage Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Demonstrates the fundamental way to access and use an icon with a specific weight. Icons are accessed as enum cases with computed properties for each weight. ```swift Ph.heart.fill ``` -------------------------------- ### Install Phosphor Icons Swift Package Source: https://github.com/phosphor-icons/swift/blob/main/README.md Add this repository as a Package Dependency in Xcode. Use the provided URL for the search bar. ```text https://github.com/phosphor-icons/swift ``` -------------------------------- ### Colored Icon Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Illustrates applying a specific color to a filled Phosphor icon using the `.color` modifier. ```swift Ph.heart.fill .frame(width: 64, height: 64) .color(.red) ``` -------------------------------- ### Build an Icon Grid Layout Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Display icons in a responsive grid layout. This example uses `LazyVGrid` to efficiently arrange icons, adapting to available screen space. ```swift LazyVGrid(columns: [GridItem(.adaptive(minimum: 50))]) { ForEach(Ph.allCases) { icon in icon.regular } } ``` -------------------------------- ### Color by State Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Illustrates coloring an icon based on a boolean state variable, useful for interactive elements like buttons. ```swift struct StateColorIcon: View { @State private var isActive = false var body: some View { Button { isActive.toggle() } label: { Ph.bell.regular .frame(width: 44, height: 44) .color(isActive ? .orange : .gray) } ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md The library is distributed via Swift Package Manager. Add the repository URL to your project's package dependencies. ```swift .package(url: "https://github.com/phosphor-icons/swift", from: "1.0.0") ``` -------------------------------- ### Format Code Source: https://github.com/phosphor-icons/swift/blob/main/CONTRIBUTING.md Run the format script to ensure code contributions adhere to the project's style guide before submitting a Pull Request. ```sh pnpm format ``` -------------------------------- ### Tinted Icon Set Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Shows a horizontal stack of icons, each tinted with a distinct color to represent different states or types. ```swift struct TintedIconSet: View { var body: some View { HStack(spacing: 16) { Ph.checkCircle.regular .frame(width: 32, height: 32) .color(.green) Ph.warning.regular .frame(width: 32, height: 32) .color(.orange) Ph.xCircle.regular .frame(width: 32, height: 32) .color(.red) } } ``` -------------------------------- ### Geometric and Abstract Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Examples of geometric and abstract shape icons available in the library. These can be used for diagrams or visual elements. ```swift Ph.triangle.regular Ph.diamond.regular Ph.hexagon.regular Ph.pentagon.regular Ph.cross.regular Ph.star.regular Ph.asterisk.regular Ph.dots.regular ``` -------------------------------- ### Ph Icon Weight Usage Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/types.md Demonstrates how to use the Ph.IconWeight enum with a SwiftUI Picker to dynamically change an icon's weight. ```swift import SwiftUI import PhosphorSwift struct IconDemo: View { @State private var weight: Ph.IconWeight = .regular var body: some View { VStack { Picker("Weight", selection: $weight) { ForEach(Ph.IconWeight.allCases) { Text(w.rawValue).tag(w) } } Ph.star.weight(weight) .frame(width: 64, height: 64) } } } ``` -------------------------------- ### Color Modifier Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Illustrates how to apply custom colors to icons using the `.color(_: Color)` view modifier. This allows for easy theming and branding. ```swift Ph.heart.fill.color(.red) ``` -------------------------------- ### Media & Playback Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Examples of icons related to media playback controls. Use these for play, pause, stop, and volume adjustments. ```swift Ph.play.regular Ph.pause.regular Ph.stop.regular Ph.skipForward.regular Ph.skipBack.regular Ph.volumeHigh.regular Ph.volumeX.regular Ph.speakerHigh.regular ``` -------------------------------- ### UI Controls Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Examples of icons representing common UI control elements such as checkmarks, crosses, plus, minus, and sliders. ```swift Ph.check.regular Ph.x.regular Ph.plus.regular Ph.minus.regular Ph.equals.regular Ph.sliders.regular Ph.toggleRight.regular Ph.toggleLeft.regular ``` -------------------------------- ### Dynamic Asset Name Construction Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md Icon asset names are built dynamically. For example, `Ph.heart.bold` loads the asset named `heart-bold`. ```swift var bold: Image { Ph.icon("\(self.rawValue)-bold") } ``` -------------------------------- ### Behavior with Icon Weights Example Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Illustrates that the `color(_:)` modifier functions identically across different icon weights (regular, bold, fill, duotone). ```swift // All of these apply the same color Ph.house.regular.color(.blue) Ph.house.bold.color(.blue) Ph.house.fill.color(.blue) Ph.house.duotone.color(.blue) ``` -------------------------------- ### Accessing Icons with Different Weights Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md Demonstrates how to access and display different icon weights (regular, fill, duotone) using the Ph enum in a SwiftUI view. Includes examples of applying color and setting frame dimensions. ```swift import SwiftUI import PhosphorSwift struct ContentView: View { var body: some View { VStack(spacing: 20) { // Regular weight horse icon Ph.horse.regular .frame(width: 64, height: 64) // Fill weight heart icon with red color Ph.heart.fill .color(.red) .frame(width: 64, height: 64) // Duotone cube icon Ph.cube.duotone .frame(width: 64, height: 64) } } } ``` -------------------------------- ### Navigation Arrows Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Examples of accessing navigation arrow icons. These are typically used for directional actions within an application's interface. ```swift Ph.arrowUp.regular Ph.arrowDown.regular Ph.arrowLeft.regular Ph.arrowRight.regular Ph.arrowUpLeft.regular Ph.arrowDownRight.regular Ph.arrowCircleLeft.regular Ph.arrowSquareOut.regular ``` -------------------------------- ### Filter Icons by Name Pattern Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Provides examples of filtering all available icon cases based on raw value string patterns. Useful for searching or grouping icons dynamically. ```swift // Get all arrow icons Ph.allCases.filter { $0.rawValue.contains("arrow") } // Get all alert icons Ph.allCases.filter { $0.rawValue.contains("warning") || $0.rawValue.contains("alert") } // Get all brand logos Ph.allCases.filter { $0.rawValue.contains("logo") } ``` -------------------------------- ### Integration of weight(_:) Method Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Illustrates the internal implementation of the `weight(_:)` method, showing how it maps an `IconWeight` case to a specific icon variant. ```swift public func weight(_ weight: IconWeight) -> Image { switch weight { case .regular: return self.regular case .thin: return self.thin case .light: return self.light case .bold: return self.bold case .fill: return self.fill case .duotone: return self.duotone } } ``` -------------------------------- ### All Cases Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Shows how to enumerate all available `Ph.IconWeight` cases using `allCases`. ```APIDOC ## All Cases Enumerate all available weights: ```swift for weight in Ph.IconWeight.allCases { print(weight.rawValue) } // Prints: "regular", "thin", "light", "bold", "fill", "duotone" ``` ``` -------------------------------- ### Display Icons in a List with Descriptions Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Demonstrates how to present a list of icons, each with its name and a descriptive label. Uses a List and HStack for layout. ```swift struct IconList: View { let icons: [Ph] = [.house, .gear, .heart, .star, .bell] var body: some View { List { ForEach(icons, id: \.self) { icon in HStack(spacing: 16) { icon.regular .frame(width: 40, height: 40) .foregroundColor(.blue) VStack(alignment: .leading) { Text(icon.rawValue) .font(.headline) Text("Icon name: \(icon.rawValue)") .font(.caption) .foregroundColor(.gray) } } } } } } ``` -------------------------------- ### Dynamic Icon Weight Selection with Picker Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Demonstrates how to use a SwiftUI Picker to dynamically select an icon weight at runtime and apply it to an icon. ```swift import SwiftUI import PhosphorSwift struct IconViewer: View { @State private var selectedWeight: Ph.IconWeight = .regular var body: some View { VStack { Picker("Weight", selection: $selectedWeight) { ForEach(Ph.IconWeight.allCases) { weight in Text(weight.rawValue).tag(weight) } } Ph.heart .weight(selectedWeight) .frame(width: 64, height: 64) .color(.red) } } } ``` -------------------------------- ### Integration with weight(_:) Method Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Illustrates how to pass an IconWeight case to the `weight(_:)` method on any icon to apply the desired weight. ```APIDOC ## Integration with `weight(_:)` Method Pass an `IconWeight` case to the `weight(_:)` method on any icon: ```swift public func weight(_ weight: IconWeight) -> Image { switch weight { case .regular: return self.regular case .thin: return self.thin case .light: return self.light case .bold: return self.bold case .fill: return self.fill case .duotone: return self.duotone } } ``` ``` -------------------------------- ### Applying Custom Colors with Opacity Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Illustrates various ways to apply colors to icons, including system colors, custom RGB values, and colors with opacity. ```swift .color(.red) // System color .color(.accentColor) // App accent .color(Color(red: 0.5, green: 0.5, blue: 0.5)) // Custom .color(.blue.opacity(0.5)) // With opacity ``` -------------------------------- ### Previewing Icons with Mock Data Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Use #Preview to display mock icons with different styles and colors in Xcode Previews. ```swift #Preview { VStack(spacing: 16) { Ph.checkCircle.fill .color(.green) Ph.warning.fill .color(.orange) Ph.xCircle.fill .color(.red) } .padding() } ``` -------------------------------- ### Basic Icon Usage Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Shows how to display a basic Phosphor icon with a specified frame size. ```swift Ph.house.regular .frame(width: 48, height: 48) ``` -------------------------------- ### Enumerating All Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md Illustrates how to iterate through all available icons using `Ph.allCases` (from CaseIterable conformance) and display them with a regular weight. This is useful for creating icon galleries. ```swift ForEach(Ph.allCases) { icon in icon.weight(.regular) .frame(width: 44, height: 44) } ``` -------------------------------- ### Sized Icon with Aspect Ratio Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Demonstrates how to size an icon while maintaining its aspect ratio using `.aspectRatio`. ```swift Ph.gear.regular .frame(width: 80, height: 80) .aspectRatio(contentMode: .fit) ``` -------------------------------- ### Enumerating All Icon Weights Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Illustrates how to iterate through all available `Ph.IconWeight` cases using `Ph.IconWeight.allCases` and print their raw string values. ```swift for weight in Ph.IconWeight.allCases { print(weight.rawValue) } // Prints: "regular", "thin", "light", "bold", "fill", "duotone" ``` -------------------------------- ### Create a Weight Picker UI Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Build a user interface element that allows users to select an icon weight. This snippet demonstrates creating buttons for each available weight. ```swift ForEach(Ph.IconWeight.allCases) { weight in Button(weight.rawValue) { selectedWeight = weight } } ``` -------------------------------- ### Weight Picker for Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Demonstrates a `Picker` control to select and display different weight variants of a Phosphor icon. ```swift Picker("Weight", selection: $selectedWeight) { ForEach(Ph.IconWeight.allCases) { weight in Text(weight.rawValue.capitalized).tag(weight) } } ``` -------------------------------- ### Building a Weight Picker UI Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Creates a custom SwiftUI UI component for selecting an icon weight, displaying the selected weight visually. ```swift struct WeightPicker: View { @State private var selectedWeight: Ph.IconWeight = .regular var body: some View { VStack { HStack(spacing: 12) { ForEach(Ph.IconWeight.allCases) { weight in Button { selectedWeight = weight } label: { Text(weight.rawValue.capitalized) .padding(8) .background(selectedWeight == weight ? Color.blue : Color.gray.opacity(0.2)) .cornerRadius(4) } } } Ph.gear .weight(selectedWeight) .frame(width: 80, height: 80) } } } ``` -------------------------------- ### Image Configuration Helper Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md A private static method for internal use that loads an image from the module bundle by asset name and applies .interpolation(.medium) and .resizable() for scaling. ```swift private static func icon(_ name: String) -> Image { Image(name, bundle: .module) .interpolation(.medium) .resizable() } ``` -------------------------------- ### Action Buttons with Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Demonstrates creating action buttons (Edit, Delete, Share) using SwiftUI Buttons, each styled with a corresponding Phosphor Icon. ```swift struct ActionButtons: View { var body: some View { HStack(spacing: 16) { Button { print("Edit") } label: { Ph.pencil.regular .frame(width: 24, height: 24) .color(.blue) } Button { print("Delete") } label: { Ph.trash.regular .frame(width: 24, height: 24) .color(.red) } Button { print("Share") } label: { Ph.share.regular .frame(width: 24, height: 24) .color(.green) } } } } ``` -------------------------------- ### Loading Bundle Resources Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md Images are loaded from the Swift Package's resource bundle using `.module`. This allows icons to be packaged with the library without being leaked into the consuming app's asset catalog. ```swift Image(name, bundle: .module) ``` -------------------------------- ### Dynamic Weight Selection Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md Shows how to select an icon's weight dynamically using the weight(_:) method, which accepts a Ph.IconWeight parameter. This is useful when the weight is not known at compile time. ```swift @State private var selectedWeight: Ph.IconWeight = .regular var body: some View { Ph.heart.weight(selectedWeight) .frame(width: 64, height: 64) } ``` -------------------------------- ### String Conversion Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Demonstrates how to access the raw string identifier for an `IconWeight` case. ```APIDOC ## String Conversion Access the raw string identifier: ```swift let weight = Ph.IconWeight.bold print(weight.rawValue) // "bold" ``` ``` -------------------------------- ### Weight Variants for Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Demonstrates accessing different weight variants for a single icon. This allows for visual customization based on design needs. ```swift Ph.star.regular // Standard weight Ph.star.thin // Hairline weight Ph.star.light // Light weight Ph.star.bold // Bold weight Ph.star.fill // Solid fill Ph.star.duotone // Two-color duotone ``` -------------------------------- ### Navigation Menu with Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Builds a navigation menu where each item includes an icon and a label. Uses NavigationLink for drill-down navigation. ```swift struct NavigationMenu: View { let menuItems: [(icon: Ph, label: String)] = [ (.house, "Home"), (.magnifyingGlass, "Search"), (.heart, "Likes"), (.user, "Profile") ] var body: some View { VStack(alignment: .leading, spacing: 0) { ForEach(menuItems, id: \.label) { NavigationLink { Text(item.label) } label: { HStack(spacing: 16) { item.icon.regular .frame(width: 24, height: 24) .color(.blue) Text(item.label) .font(.body) .foregroundColor(.primary) Spacer() } .padding(.vertical, 12) .padding(.horizontal) } } Spacer() } .background(Color(.systemBackground)) } } ``` -------------------------------- ### Icon Sizing in SwiftUI Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md Demonstrates how to resize an icon using the .frame() modifier and maintain its aspect ratio with .aspectRatio(.fit) in SwiftUI. ```swift Ph.gear.regular .frame(width: 32, height: 32) .aspectRatio(contentMode: .fit) ``` -------------------------------- ### Dynamic Weight Selection Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Shows how to dynamically change an icon's weight at runtime using a state variable. ```swift @State private var weight: Ph.IconWeight = .regular Ph.star.weight(weight) .frame(width: 64, height: 64) ``` -------------------------------- ### Create a Responsive Phosphor Icon Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Adapts icon size based on the current accessibility size category in SwiftUI. ```swift struct ResponsiveIcon: View { @Environment(\.sizeCategory) var sizeCategory var iconSize: CGFloat { switch sizeCategory { case .small, .medium: return 32 case .large, .extraLarge: return 44 default: return 40 } } var body: some View { Ph.star.fill .frame(width: iconSize, height: iconSize) .color(.yellow) } } ``` -------------------------------- ### SwiftUI Image Configuration for Phosphor Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/types.md Illustrates applying standard SwiftUI modifiers to Phosphor icon images. ```swift Ph.heart.regular .frame(width: 64, height: 64) .aspectRatio(contentMode: .fit) .foregroundColor(.red) .opacity(0.8) .rotationEffect(.degrees(45)) ``` -------------------------------- ### List All Icon Names Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Iterate through all available icons and print their raw string names to the console. This can be used for debugging or generating lists. ```swift Ph.allCases.map { $0.rawValue }.forEach { print($0) } ``` -------------------------------- ### Implement a Phosphor Icon Weight Selector Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Allows users to select and display a Phosphor icon with different weights at runtime. ```swift struct WeightSelector: View { @State private var selectedWeight: Ph.IconWeight = .regular let iconName = Ph.star var body: some View { VStack { HStack(spacing: 8) { ForEach(Ph.IconWeight.allCases) { weight in Button { selectedWeight = weight } label: { Text(weight.rawValue.capitalized) .font(.caption) .padding(6) .background( selectedWeight == weight ? Color.blue : Color.gray.opacity(0.2) ) .cornerRadius(4) } } } iconName.weight(selectedWeight) .frame(width: 80, height: 80) } } } ``` -------------------------------- ### Using Icons in ForEach with Identifiable Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md Shows how to leverage the Identifiable conformance of the Ph enum to use icons directly within a ForEach loop, creating a grid of icons. ```swift struct IconGallery: View { var body: some View { ScrollView { LazyVGrid(columns: [GridItem(.adaptive(minimum: 50))]) { ForEach(Ph.allCases) { icon in icon.regular } } } } } ``` -------------------------------- ### Identifiable Conformance for ForEach Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Shows how the `Identifiable` conformance of `Ph.IconWeight` enables its direct use within SwiftUI's `ForEach` construct for creating dynamic lists or pickers. ```swift Picker("Icon Weight", selection: $weight) { ForEach(Ph.IconWeight.allCases) { weight in Text(weight.rawValue.capitalized).tag(weight) } } ``` -------------------------------- ### Import PhosphorSwift Module Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/types.md Import the PhosphorSwift module to access its types and functionalities in your Swift project. ```swift import PhosphorSwift ``` -------------------------------- ### Identifiable Conformance Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Explains how the `Identifiable` protocol conformance allows `Ph.IconWeight` cases to be used directly in `ForEach` loops, simplifying UI development. ```APIDOC ## Identifiable Conformance The `Identifiable` protocol allows icons to be used directly in `ForEach`: ```swift Picker("Icon Weight", selection: $weight) { ForEach(Ph.IconWeight.allCases) { weight in Text(weight.rawValue.capitalized).tag(weight) } } ``` ``` -------------------------------- ### Preloading Common Icons with IconCache Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Preload frequently used icons into a static cache for faster access and reduced loading times. ```swift struct IconCache { static let commonIcons: [Ph] = [ .house, .heart, .star, .gear, .bell, .user, .magnifyingGlass, .envelope, .phone, .gear ] } struct CachedIconView: View { var body: some View { VStack { ForEach(IconCache.commonIcons, id: \.self) { icon in icon.regular .frame(width: 44, height: 44) } } } } ``` -------------------------------- ### Use Static Icon Weights Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Displays Phosphor icons with predefined weights (regular, fill, bold) directly in the code. ```swift struct IconBar: View { var body: some View { HStack(spacing: 16) { Ph.house.regular Ph.heart.fill Ph.gear.bold } .frame(height: 44) } } ``` -------------------------------- ### Iterate Through All Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Loop through all available icons in the library. This is useful for displaying a comprehensive list or catalog of icons. ```swift ForEach(Ph.allCases) { icon in icon.regular } ``` -------------------------------- ### Applying Color to Phosphor Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/types.md Demonstrates using the `.color(_:)` modifier to apply system and custom colors, including opacity, to Phosphor icons. ```swift Ph.heart.fill .color(Color.red) Ph.star.regular .color(Color.blue.opacity(0.7)) Ph.gear.bold .color(Color(red: 0.2, green: 0.5, blue: 0.8)) ``` -------------------------------- ### Dynamic Weight Selection Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md Use the `weight(_:)` method to select a weight that is not known at compile time or to switch weights dynamically. ```APIDOC ## Dynamic Weight Selection Use the `weight(_:)` method to select a weight that is not known at compile time or to switch weights dynamically: ```swift public func weight(_ weight: IconWeight) -> Image ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | weight | `Ph.IconWeight` | Yes | — | The weight variant to render | **Return Type:** `Image` — The icon image with the specified weight ``` -------------------------------- ### Icon Catalog with Search Functionality Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Implements an icon catalog with a search bar to filter icons by name. Uses LazyVGrid for displaying filtered results. ```swift struct IconCatalog: View { @State private var searchText = "" var filteredIcons: [Ph] { if searchText.isEmpty { return Ph.allCases } else { return Ph.allCases.filter { icon.rawValue.contains(searchText.lowercased()) } } } var body: some View { VStack { SearchBar(text: $searchText) LazyVGrid(columns: [GridItem(.adaptive(minimum: 50))]) { ForEach(filteredIcons, id: \.self) { icon in VStack { icon.regular .frame(width: 50, height: 50) Text(icon.rawValue) .font(.caption2) .lineLimit(1) } } } .padding() } } } ``` -------------------------------- ### Lazy Loading Icons with LazyVGrid Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Use LazyVGrid for efficient display of large icon collections, loading icons only as they become visible. ```swift struct LazyIconGrid: View { let columns = [GridItem(.adaptive(minimum: 60))] var body: some View { ScrollView { LazyVGrid(columns: columns) { ForEach(Ph.allCases, id: \.self) { icon in icon.regular .frame(width: 60, height: 60) } } } } } ``` -------------------------------- ### View Extension Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Extends the SwiftUI View protocol to apply a color to any icon or view using the `.sourceAtop` blend mode. ```APIDOC ## View Extension ### Description Provides a convenient method to apply a color to any SwiftUI View, including Phosphor icons. ### Method Signature ```swift public extension View { func color(_ color: Color) -> some View } ``` ### Usage Applies the specified `Color` to the view using the `.sourceAtop` blend mode. ``` -------------------------------- ### Enumeration Access Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph.md All icon cases can be accessed via `allCases` (provided by `CaseIterable` conformance). ```APIDOC ## Enumeration Access All icon cases can be accessed via `allCases` (provided by `CaseIterable` conformance): ```swift ForEach(Ph.allCases) { icon in icon.weight(.regular) .frame(width: 44, height: 44) } ``` ``` -------------------------------- ### Icon Size Variants Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Demonstrates how to display the same icon at different sizes using the .frame modifier. This is useful for creating visual hierarchy or fitting icons into various UI elements. ```swift struct SizedIcons: View { var body: some View { VStack(spacing: 16) { Ph.star.regular .frame(width: 24, height: 24) Ph.star.regular .frame(width: 32, height: 32) Ph.star.regular .frame(width: 44, height: 44) Ph.star.regular .frame(width: 64, height: 64) } } } ``` -------------------------------- ### Icon Tab Bar Implementation Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Creates a tab bar using SwiftUI's TabView, where each tab item is represented by a Phosphor Icon. Manages the selected tab state. ```swift struct IconTabBar: View { @State private var selectedTab = 0 var body: some View { TabView(selection: $selectedTab) { Text("Home") .tabItem { Ph.house.regular .frame(width: 24, height: 24) } .tag(0) Text("Search") .tabItem { Ph.magnifyingGlass.regular .frame(width: 24, height: 24) } .tag(1) Text("Settings") .tabItem { Ph.gear.regular .frame(width: 24, height: 24) } .tag(2) } } } ``` -------------------------------- ### Create Icon from String Name Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md A Swift extension to find an icon enum case by its raw string value. This allows for dynamic icon selection based on string identifiers. ```swift extension Ph { static func fromString(_ name: String) -> Ph? { Ph.allCases.first { icon in icon.rawValue == name } } } // Usage if let icon = Ph.fromString("heart") { icon.regular.frame(width: 44, height: 44) } ``` -------------------------------- ### Settings & Tools Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Icons representing settings, configuration, and tools, such as gears, wrenches, and hammers. Suitable for preference panels and utility sections. ```swift Ph.gear.regular Ph.wrench.regular Ph.hammer.regular Ph.screwdriver.regular Ph.tools.regular Ph.sliders.regular Ph.knob.regular Ph.toolbox.regular ``` -------------------------------- ### Display a Single Icon in a SwiftUI Button Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Demonstrates how to use a Phosphor icon within a SwiftUI Button's label. ```swift struct IconButton: View { var body: some View { Button { print("Tapped") } label: { Ph.bell.regular .frame(width: 32, height: 32) } } } ``` -------------------------------- ### PhosphorSwift Package Definition Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md Defines the Swift Package Manager configuration for the PhosphorSwift library. It specifies the library name, supported platforms, product type, and target sources. ```swift import PackageDescription let package = Package( name: "PhosphorSwift", platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)], products: [ .library( name: "PhosphorSwift", targets: ["PhosphorSwift"]), ], targets: [ .target(name: "PhosphorSwift", path: "Sources"), .testTarget(name: "PhosphorSwiftTests", dependencies: ["PhosphorSwift"]), ] ) ``` -------------------------------- ### Dynamic Weight Selection Method Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/MODULE_ARCHITECTURE.md An instance method on the Ph enum that takes an IconWeight parameter and returns the appropriate weight variant via a switch statement, enabling runtime-determined weight selection. ```swift public extension Ph { func weight(_ weight: IconWeight) -> Image { switch weight { case .regular: return self.regular case .thin: return self.thin case .light: return self.light case .bold: return self.bold case .fill: return self.fill case .duotone: return self.duotone } } } ``` -------------------------------- ### Adding Accessibility Labels to Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Enhance icon accessibility by providing descriptive labels and hints for screen readers. ```swift struct AccessibleIcon: View { var body: some View { Button { print("Save") } label: { Ph.floppyDisk.regular .frame(width: 32, height: 32) } .accessibilityLabel("Save") .accessibilityHint("Saves the current document") } } ``` -------------------------------- ### Visual Characteristics Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md A summary of the visual characteristics of each icon weight. ```APIDOC ## Visual Characteristics - **Regular** — Balanced stroke width, good for general UI use - **Thin** — Minimum stroke width, works well at small sizes with high contrast - **Light** — Reduced stroke weight, provides a refined appearance - **Bold** — Increased stroke weight, provides prominence and emphasis - **Fill** — No outlines, solid color block with internal details - **Duotone** — Two-color appearance, background and foreground layers ``` -------------------------------- ### Render Phosphor Icons in SwiftUI Source: https://github.com/phosphor-icons/swift/blob/main/README.md Import PhosphorSwift and use the Ph enum with computed properties for icons and their weights. Icons are resizable by default and can be colored using the .color modifier. ```swift import SwiftUI import PhosphorSwift struct ContentView: View { var body: some View { HStack { Ph.horse.regular .color(.accentColor) .frame(width: 64, height: 64) Ph.heart.fill .color(.red) .frame(width: 64, height: 64) Ph.cube.duotone .frame(width: 64, height: 64) } } } ``` -------------------------------- ### Select Icon Weight Dynamically Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INDEX.md Access a specific icon with a dynamically chosen weight at runtime. This is useful when the desired weight is determined by application state. ```swift Ph.star.weight(selectedWeight) ``` -------------------------------- ### Input Fields with Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Use icons within text fields for visual cues like email or password entry. Ensure icons are appropriately sized and colored. ```swift struct IconInput: View { @State private var text = "" var body: some View { VStack(spacing: 16) { HStack { Ph.envelope.regular .frame(width: 24, height: 24) .color(.gray) TextField("Email", text: $text) } .padding() .overlay( RoundedRectangle(cornerRadius: 8) .stroke(Color.gray.opacity(0.2), lineWidth: 1) ) HStack { Ph.lockOpen.regular .frame(width: 24, height: 24) .color(.gray) SecureField("Password", text: $text) } .padding() .overlay( RoundedRectangle(cornerRadius: 8) .stroke(Color.gray.opacity(0.2), lineWidth: 1) ) } } } ``` -------------------------------- ### Apply Color to a Phosphor Icon Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/INTEGRATION_GUIDE.md Shows how to set a specific color for a Phosphor icon using the .color modifier. ```swift struct ColoredIcon: View { var body: some View { Ph.heart.fill .frame(width: 64, height: 64) .color(.red) } } ``` -------------------------------- ### Common Action Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md An array of commonly used action icons for operations like search, edit, delete, share, add, and remove. ```swift let actionIcons: [Ph] = [ .magnifyingGlass, // Search .pencil, // Edit .trash, // Delete .pencil, // Edit .share, // Share .plus, // Add .minus, // Remove ] ``` -------------------------------- ### View.color(_:) Declaration Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md The declaration of the `color(_:)` extension method for SwiftUI Views. ```swift public extension View { func color(_ color: Color) -> some View } ``` -------------------------------- ### User & Profile Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Icons representing users, profiles, and related actions like adding or removing users. Useful for user management interfaces. ```swift Ph.user.regular Ph.users.regular Ph.userPlus.regular Ph.userMinus.regular Ph.smiley.regular Ph.smileyWink.regular Ph.face.regular Ph.userCircle.regular ``` -------------------------------- ### Apply Color and Opacity to Icon Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/View-Extensions.md Applies a color and adjusts the overall opacity of an icon. Transparency of the original icon is preserved, meaning only non-transparent pixels are colored. ```swift // Icon transparency is preserved Ph.star.regular .color(.blue) .opacity(0.5) // Reduces overall opacity further ``` -------------------------------- ### Icon Naming Convention Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Explains the naming convention for Phosphor icons in Swift, differentiating between enum case names (camelCase) and their raw values (kebab-case). ```APIDOC ## Icon Naming Convention ### Description Details the naming convention used for Phosphor icons within the Swift library, distinguishing between the Swift enum case names and their corresponding raw string values. ### Convention - **Enum Case:** Uses `camelCase` (e.g., `addressBook`, `airTrafficControl`). - **Raw Value:** Uses `kebab-case` (e.g., `"address-book"`, `"air-traffic-control"`). ### Accessing Raw Value Use the `.rawValue` property on an icon enum case to retrieve its string representation. ```swift Ph.addressBook.rawValue // Returns "address-book" ``` ``` -------------------------------- ### Common Brand Logos Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Accessing predefined brand logos from the library. Ensure the library is imported to use these cases. ```swift Ph.appleLogo.regular Ph.androidLogo.regular Ph.windowsLogo.regular Ph.linuxLogo.regular Ph.googleLogo.regular Ph.spotifyLogo.regular Ph.slackLogo.regular Ph.githubLogo.regular Ph.twitterLogo.regular Ph.instagramLogo.regular Ph.facebookLogo.regular Ph.linkedinLogo.regular Ph.youtubeLogo.regular Ph.tiktokLogo.regular Ph.discordLogo.regular Ph.twitchLogo.regular Ph.netflixLogo.regular Ph.amazonLogo.regular Ph.applePodcastsLogo.regular // ... and many more ``` -------------------------------- ### Toggling Icon Weights with State Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/api-reference/Ph-IconWeight.md Switches between 'fill' and 'regular' icon weights based on a boolean state variable, useful for interactive elements. ```swift struct InteractiveIcon: View { @State private var isActive = false var body: some View { Button { isActive.toggle() } label: { Ph.star .weight(isActive ? .fill : .regular) .frame(width: 44, height: 44) .foregroundColor(isActive ? .yellow : .gray) } } } ``` -------------------------------- ### Accessing Icon Raw Value Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/REFERENCE.md Shows how to retrieve the raw kebab-case string value for an icon enum case. ```swift Ph.addressBook.rawValue // "address-book" ``` -------------------------------- ### File & Document Icons Source: https://github.com/phosphor-icons/swift/blob/main/_autodocs/ICON_CATALOG.md Icons for file management, documents, folders, and related operations like archiving or deleting. Essential for file system interfaces. ```swift Ph.file.regular Ph.files.regular Ph.document.regular Ph.documentText.regular Ph.folder.regular Ph.folderOpen.regular Ph.archive.regular Ph.trash.regular ```