Home
Softono
swift-storybook

swift-storybook

Open source MIT Swift
251
Stars
4
Forks
2
Issues
41
Watchers
3 weeks
Last Commit

About swift-storybook

swift-storybook is a Swift library designed to view SwiftUI UI components in a catalog-style format directly within an iOS application. It automatically collects and displays UI components defined using native Preview macros at runtime, eliminating the need for extensive manual setup. To use the library, developers simply install the package and add the Storybook entry point view to their app's content. The tool supports previews defined in application executable modules, dynamic frameworks, and static libraries. For static libraries, it may require the -allload linker flag to ensure all preview symbols are included in the binary. This solution provides an efficient workflow for designing, reviewing, and troubleshooting UI components by offering a centralized interface to inspect various component states and configurations without launching the main application UI. The library is maintained under the MIT license and works seamlessly with SwiftUI to visualize component layouts, colors, and behaviors during dev

Platforms

Web Self-hosted macOS iOS

Languages

Swift

Storybook for iOS

This library allows you to view UI components in a catalog-style format.
In most cases, it works by simply adding a few lines of code, as it gathers SwiftUI preview codes at runtime.

storybook previewing

Setup

  1. Install this package into your project.

  2. Put the entrypoint view.

import StorybookKit
import SwiftUI

struct ContentView: View {
  var body: some View {
    Storybook()
  }
}

Example

In app executable module

#Preview("Circle") {
  Circle()
    .fill(.purple)
    .frame(width: 100, height: 100)
}

In a dynamic framework module

#Preview("Circle") {
  Circle()
    .fill(.purple)
    .frame(width: 100, height: 100)
}

In a static library module

#Preview("Circle") {
  Circle()
    .fill(.purple)
    .frame(width: 100, height: 100)
}

[!IMPORTANT] To display all preview codes in a statically linked binary, you may need to link the binary with the -all_load linker flag. This is because the linker does not load symbols into the target binary if it deems them unnecessary.

list of modules

Maintainers

License

Storybook-ios is released under the MIT license.