I'm having problems with Xcode Cloud building my SwiftUI app since I added dummy data for SwiftData for previews (in the "Preview Content" folder) with the error "Cannot find 'SampleData' in scope":
Error log
The dummy data is used in the view's previews like the following for views that use queries themselves
#Preview {
RecentListView()
.modelContainer(SampleData.shared.modelContainer)
}
and like this for others that get passed individual elements
#Preview(traits: .modifier(SampleDataPreview())) {
@Previewable @Query var workdays: [WorkDay]
NavigationStack {
SummaryView(filteredWorkdays: workdays)
}
}
Locally all previews work as expected and I can build the whole project with Xcode just fine.
I added the SampleData.swift file to the
- Development assets (in the General tab of the target)
- Copy bundle resources (in the Build phases tab of the target)
hoping this would fix the Xcode cloud build process but so far this hasn't helped and I don't really know what else to try anymore.
I'm having problems with Xcode Cloud building my SwiftUI app since I added dummy data for SwiftData for previews (in the "Preview Content" folder) with the error "Cannot find 'SampleData' in scope":
Error log
The dummy data is used in the view's previews like the following for views that use queries themselves
#Preview {
RecentListView()
.modelContainer(SampleData.shared.modelContainer)
}
and like this for others that get passed individual elements
#Preview(traits: .modifier(SampleDataPreview())) {
@Previewable @Query var workdays: [WorkDay]
NavigationStack {
SummaryView(filteredWorkdays: workdays)
}
}
Locally all previews work as expected and I can build the whole project with Xcode just fine.
I added the SampleData.swift file to the
- Development assets (in the General tab of the target)
- Copy bundle resources (in the Build phases tab of the target)
hoping this would fix the Xcode cloud build process but so far this hasn't helped and I don't really know what else to try anymore.
Share Improve this question asked Mar 24 at 21:13 user28960225user28960225 211 silver badge3 bronze badges 4 |1 Answer
Reset to default 1Wrapping all #Preview
s with #if DEBUG
makes the project build again for AppStore Connect. Seems to be an issue with the sample data in the Preview Content folder, also see:
https://stackoverflow/a/77646138/28960225
Thanks @Joakim!
#if DEBUG...
? Since it's a swift file I don't see how either Development assets or Bundle resources are relevant. – Joakim Danielson Commented Mar 24 at 21:42#if DEBUG
but wrapping all#Preview
s with it, makes it build again for AppStore Connect, so thank you! – user28960225 Commented Mar 25 at 16:04