A Swift package for closure-based delegation that automatically prevents retain cycles and memory leaks.
Delegated is a Swift package that provides a closure-based delegation system designed to prevent memory leaks and retain cycles automatically. It replaces traditional closure delegation patterns with a property-wrapper-based API that handles weak references implicitly, removing the need for manual `[weak self]` annotations. This helps developers write safer, more maintainable Swift code, particularly in iOS and macOS applications.
Swift developers, especially those building iOS, macOS, or other Apple platform applications who use delegation patterns and want to avoid common memory management issues. It's ideal for developers tired of manually managing weak references in closure-based callbacks.
Developers choose Delegated because it eliminates the boilerplate and error-prone nature of manual weak reference management in delegation, providing a type-safe, compile-time-checked alternative that automatically prevents retain cycles. Its minimal API and focus on safety make delegation both simpler and more reliable.
👷♀️ Closure-based delegation without memory leaks
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Delegated wraps self in a weak reference by default, eliminating the need for manual [weak self] annotations and preventing retain cycles, as shown in the usage examples comparing before and after code.
Uses Swift property wrappers like @Delegated for compile-time safety, reducing runtime errors and improving code reliability, with clear examples for various parameter counts.
Supports delegated functions with any number of parameters, including return values via @ReturningDelegated, as demonstrated in the README with multi-parameter and return type examples.
Provides methods to remove delegates or pipe delegation between objects, enhancing flexibility in event handling, with specific syntax for piping shown in the guide.
The README warns that Delegated 3.0 is incompatible with older versions (e.g., 0.1.2 and 2.2.0), requiring migration efforts and potentially disrupting existing codebases.
Delegated 3.0 requires Swift 5.9 and newer platforms due to variadic types, which excludes projects on legacy systems or those unable to upgrade Swift versions.
It doesn't support traditional protocol-based delegation, which might be a barrier for teams entrenched in Apple's standard patterns or needing interoperability with existing code.