最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Xcode Cloud can't build SwiftUI archive that builds locally - Stack Overflow

programmeradmin8浏览0评论

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
  • Is the file a member of the build target? Are you using #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
  • The errors look like your sample data files are missing. Did you add these files to your git repo? – dr_barto Commented Mar 25 at 9:41
  • @JoakimDanielson: The file is a build target member. So far I was not using #if DEBUG but wrapping all #Previews with it, makes it build again for AppStore Connect, so thank you! – user28960225 Commented Mar 25 at 16:04
  • @dr_barto Yes, the sample data file is in the repo but within the Preview Content folder, that seems to cause some troubles. – user28960225 Commented Mar 25 at 16:05
Add a comment  | 

1 Answer 1

Reset to default 1

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/a/77646138/28960225

Thanks @Joakim!

发布评论

评论列表(0)

  1. 暂无评论