Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: DanielSincere/IdentifiedEnumCases
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: trunk
Choose a base ref
...
head repository: DiligentRobot/IdentifiedEnumCases
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: trunk
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Dec 5, 2023

  1. Make CaseID identifiable

    mtancock committed Dec 5, 2023
    Copy the full SHA
    76ba807 View commit details

Commits on Sep 18, 2024

  1. Bump swiftSyntax

    mtancock authored Sep 18, 2024
    Copy the full SHA
    ba42b93 View commit details
Showing with 4 additions and 4 deletions.
  1. +1 −1 Package.swift
  2. +1 −1 Sources/IdentifiedEnumCases/Library.swift
  3. +2 −2 Sources/IdentifiedEnumCasesMacro/IdentifiedEnumCasesMacro.swift
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "600.0.0"),
],
targets: [
// Macro implementation that performs the source transformation of a macro.
2 changes: 1 addition & 1 deletion Sources/IdentifiedEnumCases/Library.swift
Original file line number Diff line number Diff line change
@@ -29,5 +29,5 @@
/// If the enum is `public`, the generated `ID` enum and the
/// generated `id` accessor will also be `public`
///
@attached(member, names: named(CaseID), named(caseID))
@attached(member, names: named(CaseID), named(caseID), named(id))
public macro IdentifiedEnumCases() = #externalMacro(module: "IdentifiedEnumCasesMacro", type: "IdentifiedEnumCasesMacro")
Original file line number Diff line number Diff line change
@@ -49,8 +49,8 @@ public struct IdentifiedEnumCasesMacro: MemberMacro {
}

let modifier = declaration.hasPublicModifier ? "public " : ""
let enumID = "\(modifier)enum CaseID: String, Hashable, CaseIterable, CustomStringConvertible {\n\(caseIds.map { " case \($0)\n" }.joined())\n \(modifier)var description: String {\nself.rawValue\n }\n}"
let idAccessor = "\(modifier)var caseID: CaseID {\n switch self {\n\(caseIds.map { " case .\($0): .\($0)\n" }.joined()) }\n}"
let enumID = "\(modifier)enum CaseID: String, Hashable, Identifiable, CaseIterable, CustomStringConvertible {\n\(caseIds.map { " case \($0)\n" }.joined())\n \(modifier)var description: String {\nself.rawValue\n }\n \n var id: Self { self } }"
let idAccessor = "\(modifier)var caseID: CaseID {\n switch self {\n\(caseIds.map { " case .\($0): .\($0)\n" }.joined()) }\n}"

return [
DeclSyntax(stringLiteral: enumID),