Benefits of wrapping SwiftUI preview code in #if DEBUG?

Viewed 19

Consider the preview code below:

struct SettingsView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsView()
    }
}

...compared to the same preview below, wrapped in the compiler directive:

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

I have seen many resources choose the latter over the former. What is the benefit of wrapping the preview code? It's not like previews make it to release builds, correct?

0 Answers
Related