A demo SwiftUI project showcasing how to handle rich GenAI responses in a native iOS application. This project accompanies the article From Stream to Screen: Handling GenAI Rich Responses in SwiftUI.
Project demonstrates how to parse and display streaming responses from GenAI backends that contain rich content like markdown, widgets, and interactive elements. The project implements a flexible architecture for handling different types of content in real-time.
StreamToScreen/
├── App/
│ └── Sources/
│ └── App/
│ ├── Views/
│ │ ├── Widgets/ # UI components for different widget types
│ │ └── Inputs/ # Input-related view components
│ ├── Model/
│ │ ├── Raw/ # Raw data parsing
│ │ ├── Widgets/ # Widget-specific models and builders
│ │ ├── Form/ # Form handling
│ │ ├── StreamController.swift # Main stream handling logic
│ │ ├── StreamContentBuilder.swift # Content parsing and construction
│ │ └── StreamContent.swift # Content model definitions
│ └── Resources/
├── swift-markdown-ui-main/ # Markdown rendering dependency
└── StreamToScreen.xcodeproj/ # Xcode project file
- Real-time parsing of streaming content
- Support for various UI types
- Markdown rendering
- Interactive form elements
- Error handling and recovery
- iOS 17.0+
- Xcode 16.0+
- Swift 6.0+
- Clone the repository
- Open
StreamToScreen.xcodeproj
in Xcode - Build and run the project
The project follows a modular architecture with clear separation of concerns:
StreamController
: Manages the streaming content and stateStreamContentBuilder
: Handles content parsing and widget construction- Widget System: Extensible architecture for different content types
- SwiftUI Views: Declarative UI components for each widget type
See LICENSE.md for more details.