-
|
Does anyone else find the Draft memberwise init not working? Not sure if I have some macro issues but I can't seem to make it compile properly. Given a table like: @Table
nonisolated struct Experiment: Identifiable {
let id: UUID
var interventionID: Intervention.ID
var startDate: Date = Date()
var endDate: Date?
}I assume I should be able to do #Preview {
let intervention = try! prepareDependencies {
$0.defaultDatabase = try appDatabase()
return try $0.defaultDatabase.write { db in
return try Intervention.fetchOne(db)!
}
}
NavigationStack {
ExperimentEditor(experiment: Experiment.Draft(
Experiment(id: UUID(), interventionID: intervention.id)
))
}
}Which defies the purpose of the Draft struct. Tried cleaning, reindexing etc a few times without success |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @tchardin, this is mentioned in the docs but macros can't see other macro generated code, and so FWIW it seems almost certainly like a bug that |
Beta Was this translation helpful? Give feedback.
-
|
Amazing thanks! I thought I was going crazy. |
Beta Was this translation helpful? Give feedback.
Hi @tchardin, this is mentioned in the docs but macros can't see other macro generated code, and so
#Previewcan't seeDraft. You can either use the non-macroPreviewProvideror you can define a little define helpers outside of the macro that are called from the macro.FWIW it seems almost certainly like a bug that
#Previewhas this limitation, but not sure if it will ever be fixed.