AlphaMacroKit

0.1.1

Arideno/AlphaMacroKit

What's New

Release 0.1.1

2024-02-29T08:59:56Z

What's Changed

  • Change library type to dynamic by @Arideno in #2

Full Changelog: 0.1.0...0.1.1

🐺 AlphaMacroKit

CI Swift Package Manager compatible License: MIT

AlphaMacroKit is made to enhance Swift development by providing useful Swift macros. For now this library introduces AutoNew and EnumCaseChecker macros to solve specific challenges in unit testing area.

Requirements

  • iOS 13.0+
  • macOS 10.15+
  • watchOS 6.0+
  • tvOS 13.0+
  • Swift 5.9+

Installation

Swift Package Manager

In Xcode:

In Package.swift:

dependencies: [
    .package(url: "https://github.com/Arideno/AlphaMacroKit", from: "0.1.0")
]

Usage

The AutoNew macro simplifies the creation of instances, especially for structs and enums with multiple non-optional properties. It generates a new method, providing default values and reducing boilerplate code. This is useful in unit testing as you usually need to create some stub structs for tests. For example:

extension UUID {
    static func new() -> UUID { .init() }
}

extension String {
    static func new() -> String { .init() }
}

@AutoNew
struct User {
    let id: UUID
    let name: String
    // Other properties
}

let newUser = User.new() // User(id: UUID(), name: "")
let newUser2 = User.new(name: "Test name") // User(id: UUID(), name: "Test name")

Similarly, EnumCaseChecker enhances enums by adding computed properties for each case, allowing for more readable and maintainable code. This is particularly useful in unit testing scenarios where enum states are frequently checked. Example:

@EnumCaseChecker
enum State {
    case loading
    case success
    case error(String)
}

let state = State.loading
print(state.isLoading) // true

These macros aim to streamline Swift development, making code more concise and expressive, and significantly improving the unit testing experience.

Documentation

The latest documentation for AlphaMacroKit is available here.

Feedback

If you happen to encounter any problem or you have any suggestion, please, don't hesitate to open an issue or reach out to me at andrii.moisol@gmail.com. This is an open source code project, so feel free to collaborate by raising a pull-request or sharing your feedback.

Support Open Source

If you love this library, understand all the effort it takes to maintain it and would like to support me, you can buy me a coffee by following this link:

Buy Me A Coffee

You can also sponsor me by hitting the GitHub Sponsor button. All help is very much appreciated.

License

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

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 09:10:57 GMT-0900 (Hawaii-Aleutian Daylight Time)