xcodeswiftuicloudswiftdata

Xcode Cloud can't build SwiftUI archive that builds locally


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

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.


Solution

  • Wrapping all #Previews 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.com/a/77646138/28960225

    Thanks @Joakim!