Skip to content

lalamove/RBStack

Repository files navigation

RBStack

RBStack is a straightforward library built using Swift's Result Builder, designed to create UIStackViews declaratively, much like VStack/HStack in SwiftUI.

Swift 5.9+ iOS 12+ SPM CocoaPods

This library is ideal for migrating existing UIKit code to improve readability and can potentially reduce UI code by 50%.

Requirements

  • iOS 12.0+
  • Swift 5.9+
  • Xcode 15+

Features

  • RBVStack and RBHStack to construct vertical and horizontal stack views. Kinds of child view expressions supported inside the builder closure including:
    • Optional
    • If-Else
    • For Loop
    • Array
    • Assignment statement
  • RBSpacer and RBDivider to simplify layout management.

Installation

Swift Package Manager

You can add RBStack via Xcode or by editing Package.swift.

  • Xcode: File > Add Packages... and use https://github.com/lalalmove/RBStack.git.
  • Package.swift:
dependencies: [
    .package(url: "https://github.com/lalalmove/RBStack.git", from: "1.0.0")
],
targets: [
    .target(
        name: "YourApp",
        dependencies: [
            .product(name: "RBStack", package: "RBStack")
        ])
]

CocoaPods

Add RBStack to your Podfile, then install.

platform :ios, '12.0'
use_frameworks!

target 'YourApp' do
  pod 'RBStack', '~> 1.0'
end

Then run:

pod install

Manual

Copy all files inside Sources folder into your own project.

Example

  1. This simple view uses all major RBStack components. Cell

  2. Try to build Example.xcodeproj and check more examples.

  3. You can try to preview your own code in StackPreviews.swift

About

Declarative UIStackView like SwiftUI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •