Swift Macro for SwiftUI Previews Not Recognized in Xcode

Here's a concise post for the Apple Developer Forums:


Title: Swift Macro for SwiftUI Previews Not Recognized in Xcode

Hello everyone,

I've developed a Swift macro swift-inject-preview that generates SwiftUI previews (PreviewProvider or #Preview). However, Xcode seems to ignore the previews generated by the macro, likely because it searches for PreviewProvider/#Preview or similar text in the file before macro expansion.

Has anyone encountered a similar issue or found a workaround for getting Xcode to recognize previews created through Swift macros?

Any help or insight would be greatly appreciated!

Thank you!
Daniil Voidilov

Hi,

Thanks for your interest in Previews and the tooling around it. Unfortunately there is no workaround that would enable you to get previews working with preview code generated from another macro.

Swift Macro for SwiftUI Previews Not Recognized in Xcode
 
 
Q