A Swift macro that generates memberwise initializers at any access level with default values and compile-time safety.
@MemberwiseInit is a Swift macro that automatically generates memberwise initializers for structs, eliminating the need for manual boilerplate code. It provides enhanced control over initialization parameters, including access levels, default values, and custom labels, while maintaining compile-time safety. The macro is particularly useful for Swift developers who want to reduce repetitive code and ensure consistent initialization patterns.
Swift developers building struct-heavy applications, especially those working with SwiftUI, property wrappers, or requiring fine-grained control over initializer access levels and default values.
Developers choose @MemberwiseInit because it combines the convenience of automatic initializer generation with strict safety guarantees, avoiding access level leaks and providing explicit control over initialization behavior. Unlike Swift's built-in memberwise initializer, it supports public initializers and advanced features like default values for `let` properties.
Swift Macro for memberwise initializers at any access level, with default values and compile-time safety.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Enforces compile-time checks to prevent access leaks, as shown by diagnostic errors when private properties would be exposed in public initializers, ensuring strict encapsulation.
Supports default parameter values in initializers for immutable properties using @Init(default:), a feature not available in Swift's built-in memberwise initializer.
Seamlessly works with Swift property wrappers like @State and @Binding via @InitWrapper, making it ideal for SwiftUI views and reducing common pitfalls.
Offers precise control over initializer parameters with attributes like @Init(label:) for custom labels and @Init(.ignore) to exclude properties, reducing boilerplate while maintaining intent.
Operates at syntax level and cannot infer types for all cases, such as closure typealiases, requiring manual @Init(escaping: true) annotations, as admitted in the README's automatic escaping section.
Includes experimental macros like @_UncheckedMemberwiseInit and support for actors/classes, which may lead to breaking changes or instability in future updates.
Requires understanding and applying multiple @Init attributes correctly, adding cognitive load compared to Swift's simpler built-in initializer, especially for attributed properties.
Features like _deunderscoreParameters are deprecated, indicating API churn that could confuse users and necessitate updates to maintain compatibility.