Hi everyone,
I’ve released StructuredLayout, a small Swift package that adds a declarative structural layout layer to existing UIKit projects.
The main use case is a codebase that already uses SnapKit and wants to improve layout readability incrementally, without migrating the screen to SwiftUI or replacing the existing constraint tool.
The idea
A layout is expressed with Row, Column, HStack, VStack, ZStack, and Spacer:
view.sl.layout {
VStack(spacing: 12) {
titleLabel
HStack(spacing: 8, alignment: .center) {
avatarView.size(48)
detailLabel.expand()
actionButton
}
}
}
The result builder produces native Auto Layout constraints. Structural nodes use UILayoutGuide boundaries, so they do not add layout-only container UIView instances.
Design boundaries
- It is intended for gradual adoption in UIKit/SnapKit applications.
- It does not replace SnapKit. Special relationships can continue to use
snp.makeConstraints. Row/ColumnandHStack/VStackare equivalent naming styles.- It is SwiftUI-like at the API surface, but it is not a SwiftUI runtime: there is no state-driven diffing, view identity, environment, or replacement for UIKit.
- The core package has no third-party dependencies.
Concrete comparison
The repository contains two implementations of the same Profile Card, using the same 10 business UIViews:
- SnapKit-only layout: 48 non-blank layout lines
- StructuredLayout: 29 non-blank layout lines
- Reduction in that example: 39.6%
The compared regions are marked directly in the source, and the README includes both a generated code comparison image and a short GIF that switches between the two implementations.
I also added an isolated benchmark target. In one Debug / iPhone 17 Simulator / iOS 26.5 snapshot, layout installation measured:
- SnapKit: 0.487 ms per card
- StructuredLayout: 0.564 ms per card
- Increment: about 0.076 ms per card
This is a development benchmark snapshot, not a claim that the DSL is faster than SnapKit or native Auto Layout. The main trade-off is a small abstraction cost for less repetitive and more structural layout code.
Current status
Version 0.1.5 supports iOS 14+, Swift 5.9+, Swift Package Manager, nested stacks, alignment/distribution, padding, sizing, expansion, conditionals, loops, layout handles, and SnapKit interoperability.
The roadmap currently includes Grid/wrapping layouts, responsive updates, constraint animation, and explicit guidance for reusable table/collection view cells.
I’d especially appreciate feedback from teams maintaining larger UIKit/SnapKit codebases: which API edges would block gradual adoption, and which roadmap item would be most useful first?