https://github.com/spacenation/swift-equatable
:rocket: Swift Macro for synthesizing Equatable conformance for classes and actors
https://github.com/spacenation/swift-equatable
ios macos swift swift-macro swift-package
Last synced: 9 months ago
JSON representation
:rocket: Swift Macro for synthesizing Equatable conformance for classes and actors
- Host: GitHub
- URL: https://github.com/spacenation/swift-equatable
- Owner: spacenation
- License: mit
- Created: 2024-05-28T16:33:15.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-29T06:15:20.000Z (about 2 years ago)
- Last Synced: 2025-08-27T14:02:23.062Z (10 months ago)
- Topics: ios, macos, swift, swift-macro, swift-package
- Language: Swift
- Homepage:
- Size: 10.7 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swift Equatable Macro

[](LICENSE)
This package automatically generates `Equatable` conformance for both classes and actors. This means that you do not need to manually implement the `==` operator for your classes and actors, as this package will handle it for you.
By conforming to `Equatable`, instances of your classes and actors can be easily compared for equality, which is useful for many operations such as sorting, searching, and maintaining collections. This package ensures that the generated `==` operator correctly compares all relevant properties of your classes and actors, providing a robust and efficient implementation.
**Note**: Classes must be marked as final to use this package. This ensures that the synthesized `==` operator is accurate and efficient, as it does not need to account for potential subclassing.
## Usage
Add `@Equatable` annotation to class or actor
```swift
import Equatable
@Equatable
public final class Planet {
let name: String
let mass: Mass
}
/// Expands to
extension Planet: Equatable {
public static func == (lhs: Planet, rhs: Planet) -> Bool {
lhs.name == rhs.name &&
lhs.mass == rhs.mass
}
}
```
## Installation
To use the `Equatable` library in a SwiftPM project,
add it to the dependencies for your package and your target:
```swift
let package = Package(
// name, platforms, products, etc.
dependencies: [
// other dependencies
.package(url: "https://github.com/spacenation/swift-equatable", from: "1.0.0"),
],
targets: [
.target(
// name, etc.
dependencies: [
// other dependencies
.product(name: "Equatable", package: "swift-equatable")
]
)
// other targets
]
)
```
## Contributions
Feel free to contribute via fork/pull request to the main branch. If you want to request a feature or report a bug, please start a new issue.
## Become a Sponsor
If you find this project useful, please consider becoming our [GitHub Sponsor](https://github.com/sponsors/spacenation).