Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Is it possible to use SwiftData?

Aperta
#149 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
28/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
swift

Direzione di ricerca

Start by reading the reported example in Sources/tracker/Data.swift and running xtool dev to reproduce the missing SwiftDataMacros plugin error. Investigate whether xtool can support SwiftData macro expansion; the issue gives no implementation path or tests. Done means the example builds successfully, or the project documents that SwiftData is unsupported.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

I'm really new to swift and i don't really know if it's a bug, so filing without the bug label. Thanks in advance for helping :)

if i do something like this:

import SwiftData

@Model
final class Person {
    var firstName: String
    var lastName: String
	var relatives: [Person] = []
}

compilation will fail with a massive wall of repeating errors like this:

root@48e2171c8734:/ios/tracker# xtool dev
Planning...
[1/1] Planning build
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/ios/tracker/Sources/tracker/Data.swift:4:13: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
2 | 
3 | @Model
4 | final class Person {
  |             `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
5 |     var firstName: String
6 |     var lastName: String

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:5:9: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
3 | @Model
4 | final class Person {
5 |     var firstName: String
  |         `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
6 |     var lastName: String
7 |     var relatives: [Person] = []

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:6:9: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
4 | final class Person {
5 |     var firstName: String
6 |     var lastName: String
  |         `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
7 |     var relatives: [Person] = []
8 | }

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:7:6: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
5 |     var firstName: String
6 |     var lastName: String
7 |     var relatives: [Person] = []
  |      `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
8 | }

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:4:13: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
2 | 
3 | @Model
4 | final class Person {
  |             `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
5 |     var firstName: String
6 |     var lastName: String

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:4:13: error: class 'Person' has no initializers
2 | 
3 | @Model
4 | final class Person {
  |             `- error: class 'Person' has no initializers
5 |     var firstName: String
  |         `- note: stored property 'firstName' without initial value prevents synthesized initializers
6 |     var lastName: String
  |         `- note: stored property 'lastName' without initial value prevents synthesized initializers
7 |     var relatives: [Person] = []
8 | }
/ios/tracker/Sources/tracker/Data.swift:4:13: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
2 | 
3 | @Model
4 | final class Person {
  |             `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
5 |     var firstName: String
6 |     var lastName: String

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:5:9: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
3 | @Model
4 | final class Person {
5 |     var firstName: String
  |         `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
6 |     var lastName: String
7 |     var relatives: [Person] = []

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:6:9: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
4 | final class Person {
5 |     var firstName: String
6 |     var lastName: String
  |         `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
7 |     var relatives: [Person] = []
8 | }

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:7:6: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
5 |     var firstName: String
6 |     var lastName: String
7 |     var relatives: [Person] = []
  |      `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
8 | }

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:4:13: error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
2 | 
3 | @Model
4 | final class Person {
  |             `- error: external macro implementation type 'SwiftDataMacros.PersistentModelMacro' could not be found for macro 'Model()'; plugin for module 'SwiftDataMacros' not found
5 |     var firstName: String
6 |     var lastName: String

SwiftData.Model:3:320: note: 'Model()' declared here
1 | @available(swift 5.9)
2 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
3 | @attached(member, names: named(_$backingData), named(persistentBackingData), named(schemaMetadata), named(init), named(_$observationRegistrar), named(_SwiftDataNoType), named(access), named(withMutation)) @attached(memberAttribute) @attached(extension, conformances: Observable, PersistentModel, Sendable) public macro Model() = #externalMacro(module: "SwiftDataMacros", type: "PersistentModelMacro")
  |                                                                                                                                                                                                                                                                                                                                `- note: 'Model()' declared here

/ios/tracker/Sources/tracker/Data.swift:4:13: error: class 'Person' has no initializers
2 | 
3 | @Model
4 | final class Person {
  |             `- error: class 'Person' has no initializers
5 |     var firstName: String
  |         `- note: stored property 'firstName' without initial value prevents synthesized initializers
6 |     var lastName: String
  |         `- note: stored property 'lastName' without initial value prevents synthesized initializers
7 |     var relatives: [Person] = []
8 | }
[3/6] Compiling tracker Data.swift
Error: exit(1)

is it generally possible to use swiftData, and if no, could you recommend some alternative please?

P.S. probably shouldn't affect anything, but i'm building from a docker container because i couldn't set xtool up on my Nixos host

Lingua principale
Swift
Stelle
5.5k
Fork
163
Merge medio
18h 29m
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di xtool-org/xtool

Tutte le issue di xtool-org/xtool

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.