Use SwiftUI in Share Extension
SwiftUI is an effective tool to build user interfaces. Despite its constraints mentioned in my next article, SwiftUI is capable of simple use cases, such as UI in Share Extension.
Interestingly, Apple does not allow to preview SwiftUI in the target Share Extension, showing
UnsupportedProductTypeError: Previews not supported for FooShareExtension
Previews can only be used for files in applications, frameworks, or Swift packages.
productType = com.apple.product-type.app-extension
buildable = FooShareExtension.appex
We can workaround this limitation by creating a new target then add SwiftUI files into this new target. In this new target (framework), we can use live preview for SwiftUI.