Using @Namespace in #Preview Xcode 15 gives an error message

Greetings...

I am trying to use @Namespace for my matchedGeometryEffect use case.

prior to Xcode 15 beta the following code worked just fine:

struct ChapterItem_Previews: PreviewProvider {
   @Namespace static var namespace
   
    static var previews: some View {
       ChapterItem(namespace: namespace, show: .constant(true))
    }
}

However trying to do the same within the new Xcode 15 beta #Preview Macro

#Preview {
    @Namespace var namespace
    ChapterItem(namespace: namespace, show: .constant(true))
}

produces the following error message:

Ambiguous use of 'Preview(_:traits:body:)'

May I kindly get assistance on the proper way I can get this to work in Xcode 15 beta? Please be as detail as you can since I'm still new to swiftUI as well Thank You.

Answered by Developer Tools Engineer in 755837022

The closure passed to #Preview is not a ViewBuilder so once you have more than a single line code in it the "implicit return" no longer functions and you therefore have to be explicit about which lines return. I believe the error above will go away if you change line 64 to read return ChapterItem(namespace: namespace, show: .constant(true)).

Accepted Answer

The closure passed to #Preview is not a ViewBuilder so once you have more than a single line code in it the "implicit return" no longer functions and you therefore have to be explicit about which lines return. I believe the error above will go away if you change line 64 to read return ChapterItem(namespace: namespace, show: .constant(true)).

I have the same problem

Using @Namespace in #Preview Xcode 15 gives an error message
 
 
Q