Are the #if DEBUG statements really needed for previews in SwiftUI to remove it in a release build?
17:13 06 Jun 2019

The preprocessor macro's are pretty commonly seen in the SwiftUI official tutorials/videos, e.g.:

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

Are those needed? The compiler can surely see that the struct isn't used internally and omit the whole struct since the access modifier is implicit internal right? I think that everything that conforms to PreviewProvider can be removed away, but maybe that isn't the case for every conforming object, but if it isn't used, why does Apple decides to include the preprocessor macro's?

I tried to run it in release mode and locate the compiled class in the derived data folder, but I don't understand anything about it (.o file). Can anyone confirm if we really need to include the macros to omit unused code (the ContentView_Previews type doesn't get used anywhere in the code expect for previewing which isn't used in the release build anyway) in the release build?

swift c-preprocessor swiftui