Swiftpack.co - BenedictC/SweetUI as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by BenedictC.
BenedictC/SweetUI 0.2.0
SweetUI adds a little sugar to UIKit
⭐️ 2
🕓 1 week ago
.package(url: "https://github.com/BenedictC/SweetUI.git", from: "0.2.0")

SweetUI 🍬

SweetUI adds a little sugar to UIKit. Goals:

  • Thin abstraction on top of UIKit
  • Banish storyboards and nibs
  • Declarative style for UIView subclassing
  • Reduce boiler plate code for UIViewController subclasses

Let's dig into each of these points. The core of SweetUI only depends on UIKit and Foundation and there are few methods to integrate with Combine


The follow code is all that's required to create a view controller and its view:

import UIKit
import SweetUI

class ExampleViewController: ContentViewController {

    let rootView = ZStack(alignment: .center) {
        VStack(alignment: .center) {
                .font(.preferredFont(forTextStyle: .largeTitle))
                .font(.preferredFont(forTextStyle: .subheadline))
                .text("Welcome to SweetUI")
ExampleViewController screenshot

The demo app illustrates:

  • Extract the view to a View subclass
  • Communicating with the View via a ViewModel
  • Constructing a View's layout that:
    • Abstract a layout to a LayoutView subclass
    • Uses Combine for state management
    • Keyboard avoidance
  • A FlowController, specifically NavigationFlowController

Miscellaneous Notes

Fixes for Circular reference error

  1. Create a method on the root object
  2. Communicate the data via a Combine Publisher

Adding ViewBodyProvider to an existing view

class CustomControl: UIControl, ViewBodyProvider {

let body = UILabel()

init() {
    super.init(frame: .zero)

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")


How to replace main.storyboard with code



Stars: 2
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics