Table of Contents
In the past (before Xcode 15), there was no easy way to use Xcode Previews for non-SwiftUI components.
In Xcode 15, we can easily create previews with new and more concise syntax using the
This new syntax support previewing for a wide range of view:
- UIKit (UIView and UIViewController)
- AppKit (NSView and NSViewController)
- Widget timeline providers
- Timeline entries
- Live activities
You can easily support sarunw.com by checking out this sponsor.
Offline Transcription: Fast, privacy-focus way to transcribe audio, video, and podcast files. No data leaves your Mac.
To preview any view with the new
#Preview macro, we just put the view you want to preview inside the macro.
let button = UIButton(type: .system)
button.setTitle("UIKit", for: .normal)
let button = NSButton(title: "AppKit", target: nil, action: nil)
Read more article about Xcode, Xcode Previews, WWDC23, or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.Become a patron Buy me a coffee Tweet Share
How to preview UIView in Xcode Previews
If you use UIKit, you can preview your view using Interface Builder. But you can also preview a custom view that is created programmatically using Xcode Previews.
What's new in SF Symbols 5
In iOS 17, we can animate SF Symbols with the symbolEffect modifier.