GridKit
A development-time SwiftUI library that overlays configurable layout grids on top of a running app's UI, so designers and developers can verify that views align to a grid system, respect margins/gutters, and adhere to vertical (baseline) rhythm.
Ships with a curated collection of professional grid and typographic layout presets — from classic 12-column web-style grids to magazine-inspired modular and asymmetric grids.
Platform: iOS 16+ · Swift 5.9+ · Zero dependencies · SPM
Web: gridkit-react — the same overlay, presets and JSON format for React sites.
GridKit is a debug tool: it compiles to a no-op in release builds unless explicitly force-enabled.
Installation
Add GridKit to your Package.swift:
dependencies: [
.package(url: "https://github.com/acrosa/GridKit.git", from: "0.1.0"),
]
…and list it as a dependency of your target. In Xcode: File → Add Package Dependencies… and paste the URL.
Setup
One modifier at the app root:
import GridKit
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.gridKit(.enabled(activation: .shake))
}
}
}
In non-DEBUG builds gridKit(_:) resolves to the unmodified view — no overlay window, no gesture recognizers — unless .enabled(force: true) is passed. force: true is intended for internal/TestFlight builds only.
Activation modes
| Mode | Use |
|---|
.shake | Device shake gesture (default). Note: conflicts with shake-to-undo in text-heavy apps. |
.threeFingerLongPress | Simulator-friendly. |
.floatingButton | An always-available draggable pill — tap to toggle, tap the label to configure. |
.manual | Only via the programmatic API. |
Programmatic control
GridKit.shared.show()
GridKit.shared.hide()
GridKit.shared.toggle()
GridKit.shared.apply(preset: .swissTwelveColumn)
GridKit.shared.apply(configuration: myCustomGrid)
if let url = Bundle.main.url(forResource: "brand-grid", withExtension: "json") {
try GridKit.shared.load(contentsOf: url)
}
let image = GridKit.shared.snapshot() // app + overlay composite for design review
Grid anatomy
A GridConfiguration is composed of independent, stackable layers, each individually toggleable from the control panel:
- Columns — count, gutter, outer margins; safe-area-relative or full-bleed; optional highlighted column zone for asymmetric grids.
- Rows — horizontal row grid for modular grids.
- Baseline grid — repeating lines at a fixed rhythm with every-Nth-line emphasis; derivable from a text style's line height (
BaselineSpec(deriving: .body)), tracking Dynamic Type.
- Modules — shaded intersection cells of columns × rows.
- Margins & gutters — rendered as tinted zones.
- Key lines — named guides (hanglines, folios, nav/tab bar heights) at pt offsets or fractional positions, anchored to either edge.
- Spacing ruler — opt-in edge ruler with pt ticks.
Configurations are Codable — commit shared grid definitions as JSON (see Examples/brand-grid.json) and load them at runtime.
Preset library
Sixteen presets in four categories, each with notes documenting its origin and intended use:
| Category | Presets |
|---|
| Column systems | swissTwelveColumn, eightColumn, sixColumn, fourColumnMobile, singleColumnReader |
| Baseline / rhythm | fourPointRhythm, eightPointRhythm, bodyDerivedRhythm |
| Editorial / magazine | modular3x5, modular4x6, asymmetricEditorial, heroSplit, folioGrid |
| App layouts | iosStandard, cardFeed, dashboardModules |
Presets adapt to size classes: column systems define compact-width variants (e.g. swissTwelveColumn renders 4 columns in compact width).
Every preset except heroSplit (pure golden-section key lines) includes a baseline grid, so the horizontal lines for vertical rhythm are there by default. Column and editorial grids use an 8 pt rhythm. The 12-pt-gutter grids (modular4x6, dashboardModules) use 4 pt with a 12 pt beat, and fourColumnMobile uses 4 pt with an 8 pt beat.
Control panel
Summoned by the activation gesture — or always present as a floating pill in .floatingButton mode (tap the glyph to toggle the grid, tap the label to expand). Draggable and collapsible; state persists across launches: