Skip to content

Add partial SwiftData model macro support - #10

Draft
linecodesxx wants to merge 2 commits into
xtool-org:mainfrom
linecodesxx:swiftdata-model-attribute
Draft

linecodesxx wants to merge 2 commits into
xtool-org:mainfrom
linecodesxx:swiftdata-model-attribute

Conversation

@linecodesxx

@linecodesxx linecodesxx commented Oct 30, 2026 •

Copy link
Copy Markdown

Problem

SwiftData models compiled through OpenAppleMacros fail to expand @Model and @Attribute because the server does not provide their SwiftDataMacros implementations. This prevents xtool from building applications that use these macros.

Changes

  • Register a SwiftData macro module with the plugin server.
  • Expand @Model into persistent backing storage, schema metadata, observation support, a backing-data initializer, and protocol conformances. Stored properties receive generated accessors that read and write through SwiftData, including transformable values.
  • Handle @Attribute options in schema metadata and provide basic handling of @Relationship and @Transient properties.
  • Add integration fixtures for common models, optionals, observers, escaped identifiers, transformable attributes, relationships, and invalid declarations.

Support is partial: additional diagnostics and edge cases still need verification, including compatibility with Xcode 27.

Xcode 26.5 and 27 comparison

The table covers differences identified in Apple's published documentation, not an exhaustive SDK diff. The Xcode 27 swiftinterface and macro expansions have not been compared directly.

Area Xcode 26.5 / SDK 26.5 Xcode 27 / SDK 27 Status in this PR
Swift compiler Swift 6.3 Swift 6.4 The project targets Xcode 27; only Xcode 26.5 was used for local macro comparisons.
@Model and @Attribute Available and covered by the fixtures below. Available, but their exact expansion has not been compared with 26.5. Initial implementations added; Xcode 27 behavior and additional edge cases remain unverified.
@Attribute(.codable) The option is new in the 27 platform releases. Allows SwiftData to persist supported Codable types as encoded data. No explicit compatibility claim or test: the SDK 27 option and Apple's expansion were not available for local comparison.
Sectioned @Query The new sectionBy: support is unavailable. Adds sectioned query results. Not implemented here: this PR targets model and attribute macros; @Query is a separate unsupported macro in this project.
ResultsObserver and HistoryObserver New observer APIs are unavailable. Adds APIs to observe query results and persistent history. Not implemented here: these are SwiftData framework APIs, while this project reimplements compiler macros.
@Relationship and @Transient Basic cases were compared with Apple. Exact diagnostics and expansion have not been compared. Basic handling is included because models can use these annotations; comprehensive option and diagnostic coverage is not included yet.

Sources: Apple's Xcode SDK requirements and What's new in SwiftData.

Validation

  • 17 SwiftData integration fixtures match Apple macro expansion with Xcode 26.5 (OAM_IGNORE_XCODE_VERSION=1).
  • Built and ran a small SwiftData program using the custom plugin server; in-memory insert, fetch, and update succeeded.
  • The full suite on Xcode 26.5 reported 31 mismatches in existing SwiftUI and FoundationModels tests. The repository tracks Xcode 27.0.0, so these results do not establish Xcode 27 compatibility.

Xcode 27 has not been tested locally because it requires an Apple silicon Mac; the available machine uses an Intel-compatible processor.

Help wanted

Contributions are welcome, especially from anyone who can test the macro expansions against Xcode 27 on Apple silicon. Help with the remaining edge cases, diagnostics, and unverified SwiftData 27 behavior would also be appreciated.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant