I'm converting XCP to #Preview macro and I was wondering if it's possible to make preview like this below.
#Preview {
struct DemoView: View {
// make view...
}
DemoView()
}
Is that possible? If so please let me know. If not, please explain..
#Preview
macro conforms to thePreviewRegistry
protocol, which has a static propertypreview
to locate previews at runtime. It returnsDeveloperToolSupport.Preview
, and can contain a View or even a ViewController from UIKit in its body parameter.Your example code will not execute because you're missing
return
for theDeveloperToolSupport.Preview
body. Basically, function builder will not work here. (which bypassreturn
keyword)