A comprehensive Swift utilities package providing powerful extensions, reactive dependencies, and architectural patterns for modern iOS development.
Utilities is a modular package designed to accelerate iOS development by providing battle-tested extensions, dependencies, and architectural patterns. Built with Swift 6's strict concurrency and modern SwiftUI in mind, it eliminates boilerplate and promotes consistent, maintainable code.
Comprehensive extensions for Swift's standard types that make common operations more intuitive:
- Array & Collection: Safe subscripts, chunking, duplicate handling, and functional operations
- String: Validation, formatting, case conversion, and trimming utilities
- Date: Intuitive manipulation, formatting, and comparison methods
- Dictionary: JSON conversion, key mapping, and safe access patterns
- Double: Formatting, rounding, and range operations
- Optional: Enhanced unwrapping, conditional operations, and nil-coalescing helpers
- URL: File system helpers, query parameter handling, and safe operations
- Encodable: Data conversion, JSON formatting, and file operations
Modern SwiftUI modifiers and helpers for cleaner view code:
- View: Accessibility helpers, conditional modifiers, layout utilities, and platform-specific code
- Color: Hex initialization, color manipulation, and semantic colors
- Font: Semantic sizing, custom font creation, and dynamic type support
- Animation: Spring presets, custom timing curves, and transition helpers
- Binding: Transformations, nil-coalescing, and debugging utilities
- EdgeInsets: Convenience initializers and arithmetic operations
- GeometryProxy: Grid calculations, percentage sizing, and debugging
- Image: Sizing, styling, effects, and async loading support
Thread-safe, testable dependencies using Point-Free's Dependencies pattern:
- KeyboardObserver: Monitor keyboard state and animations with async streams
- ScreenReader: Access screen dimensions and safe area information
- Built-in support for live, preview, and test implementations
Revolutionary pattern for organizing complex Composable Architecture reducers:
- ActionBranch: Route specific action types to focused handlers
- ScopedBranch: Isolate state access for better encapsulation
- BranchBuilder: Declarative, SwiftUI-like syntax for composing branches
- Before/after hooks for cross-cutting concerns
- Eliminates "massive reducer syndrome"
Enhanced functionality for Swift protocols:
- CaseIterable: Random selection, cycling, and filtering
- Comparable: Clamping, range checking, and ordering utilities
- Hashable: Hash combining, set operations, and equality helpers
- RawRepresentable: Safe initialization, validation, and UserDefaults support
Add Utilities to your Package.swift
:
dependencies: [
.package(url: "https://github.com/yourusername/utilities", from: "1.0.0")
]
Or in Xcode:
- File β Add Package Dependencies
- Enter the repository URL
- Select version and add to your target
// Safe array access
let value = array[safe: 5] // Returns nil instead of crashing
// String validation
if email.isValidEmail {
// Process valid email
}
// Date manipulation
let nextWeek = Date().adding(weeks: 1)
Text("Hello")
.fontSize(.large, weight: .semibold)
.visible(isShowing)
.cardStyle()
@Reducer
struct Feature {
var body: some ReducerOf<Self> {
Reduce { state, action in
// Core logic
return .none
}
.branches {
Branch(\.view, handleViewActions)
Branch(\.delegate, handleDelegateActions)
ScopedBranch(state: \.child, action: \.child, handleChildActions)
}
}
}
- iOS 17.0+ / macOS 14.0+ / tvOS 17.0+ / watchOS 10.0+
- Swift 6.1+
- Xcode 16.0+
- swift-dependencies - Dependency injection system
- swift-composable-architecture - For Branch utilities
Each module is self-contained and can be imported independently, allowing you to use only what you need without bloating your app.
All dependencies use actor isolation for thread-safe operations in concurrent environments.
Every dependency includes test and preview implementations, making unit testing and SwiftUI previews seamless.
Written with Swift 6's strict concurrency checking enabled, ensuring safe concurrent code.
- Use safe subscripts for array access to prevent runtime crashes
- Leverage semantic font sizes for consistent typography
- Apply TCA branching to keep reducers focused and testable
- Prefer protocol extensions over global functions for discoverability
- Test with provided test implementations for predictable behavior
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Utilities is available under the MIT license. See the LICENSE file for more info.
- Point-Free for their excellent Dependencies and Composable Architecture libraries
- The Swift community for inspiration and best practices