Preview Content Folder

What exactly does this mean:
‘This group is a special group inside the Xcode project that allows you to add mocked code and data to be used inside Xcode Previews. When you later compile the app, Xcode doesn’t include the content of this group in the build’?

Does it mean that Xcode identifies this group by the name ‘Preview Content’ and therefore behaves differently, not compiling this group?
Or does Xcode not compile this group because it contains only JSON and asset files?
Or are these files used exclusively in SwiftUI previews?

Hi @shioramashvili,

Xcode does recognize this group as a “special” group and only compiles it in development. You see, the compiler will check all the code that is used inside the main project. When it finds code that is not used, the linker will remove this code from the binary (when compiling for production). We call this “dead code”. However, during development, this code is compiled so that you can use it in Xcode Previews. This is not limited to JSON files and assets, it can be Swift files or any other asset you may need during development.

The assets (images, colors, swift files, json files) that you create in this folder should never be used inside the main application, only in Xcode previews and for testing purposes. Otherwise, you’ll get a compiler error when you try to archive your project.

Hope this answers your questions.

2 Likes

Yes, thank you Renan