SwiftUI Preview’s useful features that can improve your productivity 20x times
If you have an m1 mac, use SwiftUI Preview. It will increase your productivity tremendously. SwiftUI’s Preview is just as productive as Flutter’s hot reload. But if you use intel mac, give up. You will hear the airplane take off. Today we will take a look at some useful features of SwiftUI preview.
Prepare UI
I prepared a sample view with a cat image.
[1] Show multiple devices
With .previewDevice
modifier, you can show multiple devices in your Preview Screen. This is especially useful when you need to create responsive layout. You can also render IPad, Mac, Watch, any platform you choose.
[2] Dynamic Fonts Test
Iphone users can set their own font size in each device. You can test dynamic fonts with your preview.
If you want to test more than one font size, then loop all available sizes.
[3] Dark & Light Mode
You can also see your preview in the dark or light mode. This is really useful.
[4] sizeThatFits
If you want to create an individual view component instead of entire screen, use .sizeThatFits
. Your view is displayed without iPhone behind.
Conclusion
SwiftUI Preview Tips
- Test multiple device screens
- Test Dynamic Font Sizes
- Test Light & Dark Mode
- Use sizeThatFits when you need to create an individual component