Do Xcode 15 UIKit views with storyboards work with #Preview macro?

360 views Asked by At

I'm just trying to get #Preview to work with a UIKit ViewController. See screenshot for details. Nothing special, IMHO instantiating the VC in the #Preview should just work. But all of the graphical elements that I have in the Main.storyboard don't appear. I just get a white screen.

Is this a general limitation of the macro or am I missing something?

enter image description here

1

There are 1 answers

2
Claus Jørgensen On BEST ANSWER

You're not loading the storyboard, just the ViewController. If you want the storyboard content as well you'd need to load it just like you would in actual code, e.g.

#Preview {
    UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()!
}

xcode preview of storyboard