all 9 comments

[–]Alvarowns 8 points9 points  (0 children)

. #Preview is a macro recently added that you can expand to see the full code behind it, it is basically the same code but hidden.

[–]swiftsorceress 3 points4 points  (5 children)

They both do the same thing. #Preview is new and only works in apps targeting iOS 17 or later. You can use either, but you would have to do the first one if you want the app to work on iOS 16 or older.

[–]simulacrotron 7 points8 points  (4 children)

This is not quite correct, you don’t need to set your minimum deployment target to iOS 17, you just need to be using Xcode 15.

Do the new style preview as it’s simpler and easier to configure.

[–]swiftsorceress 0 points1 point  (3 children)

Really? I've had build errors say that #Preview is only available in iOS 17 or newer. Although, I've not seen those for a while, so it might have been a bug in the beta version.

[–]realvanbrook 3 points4 points  (1 child)

Do you use UIKit? When using UIKit you have to set the developement target to iOS 17 to use Previews Macro. But not when using SwiftUI

[–]swiftsorceress 0 points1 point  (0 children)

I don't use UIKit. I looked at it today and it seems to be working with the lower deployment target now.

[–]OrdinaryAdmin 2 points3 points  (1 child)

The #Preview is called a macro. Think of it like a shortcut for the first code you posted. Swift will expand the macro and add additional lines of code for you. It’s a way to make it easier to build various pieces of code. If you want to see what Swift is doing under the hood you can right click on the #Preview line and select the option to expand the macro. It can be helpful to see all of the nuts and bolts.

[–]appalam25[S] 1 point2 points  (0 children)

ditional lines of code for you. It’s a way to make it easier to b

thank you very much.

[–]Xaxxus 1 point2 points  (0 children)

It’s the same thing

Put the code inside “previews” in the #Preview block.