Skip to content

IOS-1269 feat: add AddComponentModifier Macro#54

Merged
ElonPark merged 7 commits into
mainfrom
feature/elon/IOS-1269-add-AddComponentModifier-macro
Sep 16, 2025
Merged

IOS-1269 feat: add AddComponentModifier Macro#54
ElonPark merged 7 commits into
mainfrom
feature/elon/IOS-1269-add-AddComponentModifier-macro

Conversation

@ElonPark

Copy link
Copy Markdown
Member

Background (Required)

  • IOS-1269
  • Introduced Swift Macros support to reduce boilerplate code when creating component modifiers in KarrotListKit framework
  • Component developers frequently write repetitive setter methods that follow the same pattern, which leads to maintenance overhead and potential inconsistencies
  • Goal is to automate the generation of these methods using compile-time code generation with Swift Macros

Changes (Required)

Swift Macros Infrastructure Setup

  • Updated Swift tools version from 5.5 to 5.9 in Package.swift
  • Added swift-syntax dependency (509.0.0..<602.0.0) for macro compilation support
  • Created new KarrotListKitMacros target with compiler plugin support
  • Added KarrotListKitMacrosTests target for macro testing

@AddComponentModifier Macro Implementation

  • Implemented @AddComponentModifier peer-attached macro in AddComponentModifier.swift
  • Created AddComponentModifierMacro.swift with logic to:
    • Analyze closure property types
    • Generate method signatures by removing "Handler" suffix
    • Inherit access level from parent struct
  • Added support utilities:
    • AccessLevelModifier.swift for handling access levels (public, internal, private)
    • KarrotListKitMacroError.swift for error handling
    • KarrotListKitPlugin.swift for compiler plugin registration

Sample App Updates

  • Updated VerticalLayoutItemComponent.swift with macro usage examples:
    • Simple handler without parameters
    • Handler with single value parameter
    • Handler with multiple parameters
    • Handler with named parameters
  • Updated Package.resolved to version 3 format

CI/CD Pipeline Modernization

  • Upgraded GitHub Actions workflow environment:
    • macOS: 14 → 15
    • Xcode: 15.2/16.1 → 16.4
    • iOS Simulator: iPhone 15 (iOS 17.2) → iPhone 16 (iOS 18.1)
  • Added strategy matrix to test both Debug and Release configurations
  • Added check-macro-compatibility job for Swift macro compatibility verification

Test Methods (Required)

Unit Tests Added

  • AddComponentModifierMacroTests.swift (167 lines) covering:
    • Macro behavior with different access levels (public, internal, private)
    • Error handling for invalid property types
    • Method generation from various closure signatures
    • Proper "Handler" suffix removal from property names

CI/CD Testing Strategy

  • Automated testing in both Debug and Release configurations
  • Cross-platform compatibility testing with latest Xcode 16.4
  • Swift macro compatibility verification in separate job
  • Sample app build validation with macro-generated code

Review Notes

Key Review Points

  • The @AddComponentModifier macro eliminates boilerplate code by automatically generating setter methods for closure properties
  • Access level inheritance ensures generated methods match the visibility of their parent struct
  • Swift tools version upgrade to 5.9 is required for macro support

Design Decisions

  • Chose peer-attached macro approach to preserve original property while adding convenience methods
  • "Handler" suffix removal convention aligns with Swift naming patterns (e.g., onTapButtonHandleronTapButton() method)
  • Comprehensive error handling for compile-time feedback when macro is misused

Future Considerations

  • Could extend macro to support additional modifier patterns beyond closures
  • Consider adding customization options via macro parameters
  • Monitor Swift Macros evolution for potential improvements

Technical Dependencies

  • Requires Xcode 15.0+ for Swift Macros support
  • swift-syntax package version must be compatible with Swift compiler version

@ElonPark ElonPark self-assigned this Sep 15, 2025
@ElonPark ElonPark added the Feature New feature or request label Sep 15, 2025
@ElonPark ElonPark requested a review from stleamist September 15, 2025 03:48
@ElonPark ElonPark force-pushed the feature/elon/IOS-1269-add-AddComponentModifier-macro branch 4 times, most recently from 89f98b7 to 1169037 Compare September 15, 2025 04:59
@ElonPark ElonPark changed the base branch from main to task/ray/NO-TICKET-resolve-test-crash September 15, 2025 05:29
@ElonPark ElonPark force-pushed the feature/elon/IOS-1269-add-AddComponentModifier-macro branch from 1169037 to 938a49f Compare September 15, 2025 05:29
Base automatically changed from task/ray/NO-TICKET-resolve-test-crash to main September 15, 2025 05:36
@ElonPark ElonPark force-pushed the feature/elon/IOS-1269-add-AddComponentModifier-macro branch from 938a49f to d34bde9 Compare September 15, 2025 05:59
@ElonPark ElonPark force-pushed the feature/elon/IOS-1269-add-AddComponentModifier-macro branch 5 times, most recently from cdebb6d to 17e33e9 Compare September 15, 2025 09:05
@ElonPark ElonPark force-pushed the feature/elon/IOS-1269-add-AddComponentModifier-macro branch from 17e33e9 to 372d8c6 Compare September 15, 2025 09:09

@jaxtynSong jaxtynSong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 👍

@ElonPark ElonPark merged commit a8641f9 into main Sep 16, 2025
4 checks passed
@ElonPark ElonPark deleted the feature/elon/IOS-1269-add-AddComponentModifier-macro branch September 16, 2025 07:09
@ElonPark ElonPark added this to the v4.6.0 milestone Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants