How can I show two or more different variants in Xcode using the new #Preview
macro?
Without the macro, this was possible:
struct TutorialView_Previews: PreviewProvider {
static var previews: some View {
MyAwesomeView(title: "Title One", hideSomePart: true)
.previewDisplayName("Hidden some part")
MyAwesomeView(title: "Title Two", hideSomePart: false)
.previewDisplayName("Showing all parts")
}
}
But with the new macro, this isn’t compiling:
#Preview {
MyAwesomeView(title: "Title One", hideSomePart: true)
.previewDisplayName("Hidden some part")
MyAwesomeView(title: "Title Two", hideSomePart: false)
.previewDisplayName("Showing all parts")
}
2
Answers
Turned out to be a simple fix:
Using .previewDisplayName("…") does not work for me. I got it working doing it like this: