The #if / #endif compiler conditionals surrounding PreviewProvider types have been removed from SwiftUI templates. PreviewProviders aren’t properly removed from built products when archived. (51539802)
I don't quite understand what it mean? How does the PreViewProvider get strip out now?
I have some extra code only needed for preview, I should surround them with #if DEBUG / #endif, yes?
That's dead code, because it's never actually used by your program (well, unless you are using it for some reason). Perhaps there was a bug that was preventing it from being optimised out, and now has been fixed. Obviously, I am speculating because I don't work on SwiftUI.
I know this code is stripped when not in DEBUG build. I want to know what's changed in the latest Xcode to do this now without having to surround them with #if DEBUG / #endif...
I know Preview is for DEBUG only. I want to know about how Xode now do the stripping out without the need to surround them in #if DEBUG / #endif.
Just for the record, that release note probably contains a typo, because its literal meaning makes no sense.
Presumably it meant to say this instead:
The #if/#endif compiler conditionals surrounding PreviewProvider types have been removed from SwiftUI templates. PreviewProviders [are now] properly removed from built products when archived[, even without the compiler conditionals]. (51539802)
I just want to know why the latest generated dont have #if DEBUG / #endif. So from the comment below, the release note has a typo? I don’t understand it as it’s written.
I want to know how, with no #if DEBUG / #endif, the code is stripped in the end. Do you mean this is done with compiler dead code elimination? I want to know because I have extra code that’s only needed for SwiftUI Preview. Do I need to surround them with #if DEBUG / #endif or not?
As I understand the text. Yes, it is done during optimization period, and no, you don't need to surround them (since Xcode doesn't surround them either).
I'm a little late, but I just had to make note of this because the confusion is all over the web and it's quite comical. Turns out, it was under "Resolved Issues" and the title of the resolved ticket was "PreviewProviders aren’t properly removed from built products when archived. (51539802)".