Swift Package to build UIKit in a functional manner

What's New



ViewKit 1.0.0

We are thrilled to announce the first stable release of ViewKit!

This is a significant milestone for us, showcasing our commitment to providing a simple, reusable, and efficient UIKit-based framework that makes building interfaces in Swift more enjoyable and less time-consuming. ViewKit 1.0.0 is ready for production use, bringing a host of features and improvements:

  • Fluent Interfaces and Result Builders: Write less boilerplate and make your UIKit code more declarative.
  • Method Chaining: Enjoy most of UIKit's customization properties brought to ViewKit in the method chaining way.
  • Stacks: Leverage VerticalStack and HorizontalStack, reminiscent of SwiftUI's VStack and HStack, with added versatility.
  • Filler Views: Use filler views as you would use SwiftUI's Spacer, providing flexible space within your interfaces.
  • UIView Composition: Use UIView in a ZStack-like manner, supercharging your interface building.
    We want to thank everyone who has contributed to ViewKit, whether by submitting PRs, filing issues, or providing feedback. We're excited to continue improving and expanding ViewKit.

To use ViewKit 1.0.0, add the following line to your Swift Package dependencies:

.package(url: "", from: "1.0.0")

As always, we appreciate any feedback. If you have suggestions, issues, or just want to say hi, please don't hesitate to reach out!

Feel free to modify it to better suit your needs.


ViewKit is a lightweight and user-friendly Swift package that brings SwiftUI-like, declarative syntax to UIKit. It provides a way to write UIKit code in a declarative and chainable manner, similar to SwiftUI, making UIKit development more streamlined and approachable. Most customization properties available in UIKit are supported in ViewKit using method chaining for a more fluid and readable syntax.



You can install ViewKit using Swift Package Manager. Simply add the following line to your Package.swift file:

dependencies: [
    .package(url: "", from: "1.0.0")



ProgrammaticView is the main protocol in ViewKit for creating views. Here's how you can use it:

Define your view by implementing the ProgrammaticView protocol and providing your layout within the body property.

Here's an example:

import ViewKit

final class MyView: ProgrammaticView {

    var body: UIView {
        VerticalStack(spacing: 20) {
            UILabel("Hello, world!")
                .font(.preferredFont(forTextStyle: .largeTitle))

            UIButton("Tap me!") { _ in print("Tapped") }
                .font(.preferredFont(forTextStyle: .title1))

VerticalStack and HorizontalStack

VerticalStack and HorizontalStack work similarly to VStack and HStack in SwiftUI. They are used to stack views vertically and horizontally, respectively.

VerticalStack(spacing: 20) {
    // Your views here

HorizontalStack(spacing: 20) {
    // Your views here

Additionally, UIView can be used similarly to ZStack in SwiftUI, for stacking views on top of each other.


Filler works similar to Spacer in SwiftUI. It pushes adjacent views away, taking up all available space.

HorizontalStack(spacing: 20) {

In this example, the "Hello" and "World" labels will be pushed to opposite sides of the screen, with all the remaining space in between being filled by the Filler.


You can use this ProgrammaticView with a custom ViewController that takes a ProgrammaticView in its constructor and sets it as its view.

Here's an example:

let viewController = ViewController(with: MyView())


You can also preview your ViewKit views in the Xcode canvas by embedding your ProgrammaticView in a PreviewContainer like so:

import SwiftUI

struct MyView_Previews: PreviewProvider {
    static var previews: some View {
        PreviewContainer {

Advanced Concepts

Result Builders and Fluent Interfaces

ViewKit leverages Swift's result builders and fluent interfaces to create a more declarative syntax and reduce boilerplate code. This helps keep your UIKit code clean and easy to understand.


ViewKit is available under the MIT license. See the LICENSE file for more information.

Swift Package Index

Check out on Swift Package Index: [](


  • Swift Tools 5.7.0
View More Packages from this Author


  • None
Last updated: Tue May 30 2023 08:43:04 GMT-0500 (GMT-05:00)