Skip to content

mrbagels/utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Utilities

A comprehensive Swift utilities package providing powerful extensions, reactive dependencies, and architectural patterns for modern iOS development.

Swift Version Platform License Version

Overview

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.

Features

🎯 Foundation Extensions

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

🎨 SwiftUI Extensions

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

πŸ“± Platform Dependencies

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

πŸ—οΈ TCA Branch Utilities

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"

πŸ”§ Protocol Extensions

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

Installation

Swift Package Manager

Add Utilities to your Package.swift:

dependencies: [
    .package(url: "https://github.com/yourusername/utilities", from: "1.0.0")
]

Or in Xcode:

  1. File β†’ Add Package Dependencies
  2. Enter the repository URL
  3. Select version and add to your target

Usage Examples

Foundation Extensions

// 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)

SwiftUI Extensions

Text("Hello")
    .fontSize(.large, weight: .semibold)
    .visible(isShowing)
    .cardStyle()

TCA Branching

@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)
        }
    }
}

Requirements

  • iOS 17.0+ / macOS 14.0+ / tvOS 17.0+ / watchOS 10.0+
  • Swift 6.1+
  • Xcode 16.0+

Dependencies

Architecture & Design

Modular Structure

Each module is self-contained and can be imported independently, allowing you to use only what you need without bloating your app.

Thread Safety

All dependencies use actor isolation for thread-safe operations in concurrent environments.

Testing Support

Every dependency includes test and preview implementations, making unit testing and SwiftUI previews seamless.

Modern Swift

Written with Swift 6's strict concurrency checking enabled, ensuring safe concurrent code.

Best Practices

  • 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

Contributing

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.

License

Utilities is available under the MIT license. See the LICENSE file for more info.

Acknowledgments

  • Point-Free for their excellent Dependencies and Composable Architecture libraries
  • The Swift community for inspiration and best practices

About

A collection of utilities frequently used in my independent projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages