How dogo/sketchkit works
Project Type and Purpose
• Type: Open-source Swift library (not a client app), distributed via CocoaPods, SPM, Carthage.
• Purpose: Provide a lightweight, pure-Swift DSL (“domain-specific language”) wrapper around Apple’s Auto Layout APIs, making constraint creation more concise and type-safe.
File Structure
• Top-level configuration & metadata
– CI/CD: .github/workflows/{Testing.yml, PublishDocumentation.yml}
– Linting & formatting: .swiftlint.yml, .jazzy.yaml, .tool-versions, Dangerfile
– Packaging: Package.swift, SketchKit.podspec, Gemfile
• Sources/SketchKit
– Constrainable.swift: protocol bridging UIView/UILayoutGuide to the DSL
– Extensions/: anchor definitions and safe-area helpers
– KeyboardLayoutGuide.swift: custom layout guide for keyboard avoidance
– SketchKitDSL.swift: entry point & internal DSL execution engine
• Tests/SketchKitTests
– Organized by feature (Anchors, Addons, SafeArea, Helpers) verifying each extension and protocol
README for Additional Insights
• Core functionality description
• Usage example showing:
– UIView.layout.applyConstraint { view in … }
– Generation of NSLayoutConstraint under the hood
• Supported platforms (iOS, tvOS, macOS) and Swift versions
• Publication targets (CocoaPods, SPM, Carthage)
Main Components & Their Interactions
a. Client App
– Your view code calls import SketchKit and uses view.layout.applyConstraint { … }.
b. SketchKit DSL Engine
– SketchKitDSL: orchestrates the collection and activation of constraints.
c. Constrainable Protocol & Extensions
– Adapts UIView/UILayoutGuide to the DSL API.
– Provides anchor methods (centerXAnchor(equalTo:…), leadingAnchor(equalTo:…), etc.).
d. Anchor Types & Safe-Area Add-ons
– Extension modules implement specific anchors and safe area relatives.
e. Underlying Auto Layout API
– Apple’s NSLayoutAnchor & NSLayoutConstraint
– Activation (constraint.isActive = true) managed by the DSL engine.
f. KeyboardLayoutGuide
– Custom UILayoutGuide to handle keyboard appearance/disappearance.
Architectural Patterns & Design Principles
• DSL / Fluent Interface pattern: chaining anchor methods
• Protocol extension: Constrainable protocol extends UIView and UILayoutGuide uniformly
• Separation of concerns:
– DSL definitions in Extensions
– Execution & activation logic in SketchKitDSL
– Distribution definitions in Podspec/Package.swift
• Test organization mirrors extension modules to ensure complete coverage