Unable to archive Xcode project with Development Assets content in Preview Providers

Originator:joshua.jaslow
Number:rdar://FB9712336 Date Originated:10/18/21
Status:Open Resolved:
Product:Xcode Product Version:Xcode Version 13.0 (13A233)
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
 
Basic information
Please provide a descriptive title for your feedback:
Unable to archive Xcode project with Development Assets content in Preview Providers
Which area are you seeing an issue with?
Xcode
What type of feedback are you reporting?
Incorrect/Unexpected Behavior
Details
What version of Xcode are you using?
Xcode Version 13.0 (13A233) 
Description
Please describe the issue:
There are two issues here:

1) Xcode is not performing dead code stripping on anything that contains references to objects marked as Development Assets. Thus, the archive build fails because it can't find the reference to the preview object. (At least, this shows that marking a file as a Development Asset works correctly).

2) Xcode is allowing PreviewProvider objects to be built for release. This should not happen, since PreviewProvider objects have no use outside of Xcode, and should not be shipped in the final binary in the first place. This, too, contributes to the build error when Archiving using the Development Assets.
Please list the steps you took to reproduce the issue:
The attached sample project does all of this, but here are the steps to recreate the issue nonetheless:

1) Create a new project in SwiftUI
2) Make some dummy model that a simple view will consume
3) Add the file path for this dummy object to the Development Assets section of the project file
       - Adding this file to the pre-generated Preview Content folder works as well
4) Use that static preview object in the previews for your SwiftUI view
5) Do a normal build - should build without errors
6) Make an archive build - should throw a build error saying it can’t find your object
What did you expect to happen?
I expect Xcode to archive my project without any build errors. Although I have no way of knowing whether any PreviewProvider objects made their way into the final binary (not counting the use of #if DEBUG flags), I would expect them not to be there.
What actually happened?
The archive build errors out. I get the error "Cannot find '<Development Asset object>' in scope". This means that Xcode is attempting to build an object for release with a reference to another object that has been marked as debug only. Normally, this would be a helpful error, but in this case the PreviewProvider objects shouldn't be built for release at all. See attached sample project.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!