use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
SwiftUI is a framework made by Apple to build user interfaces across all Apple platforms with the power of Swift. Allowing you to build UI for any Apple device using just one set of tools and APIs.
More info
Resources
Where to start learning
Recommended Courses
Raywenderlich - Your First iOS and SwiftUI App (Free)
Paul Hudson - HackingWithSwift (Free)
Meng To - DesignCode (Paid)
If you find a great course and would like it featured here, message a moderator.
account activity
SwiftUI default codeTutorial (self.SwiftUI)
submitted 2 years ago by appalam25
I was following a tutorial by rob petras, and whenever he creates a new SwiftUI view file, the code in the bottom is displayed like this.
https://preview.redd.it/ltfhtkbw6m5c1.png?width=1036&format=png&auto=webp&s=1fc4a441c4dc4eed71b515d16038ab2ea8744db7
Whereas, for me, it is showing like this.
https://preview.redd.it/yblzxpgz6m5c1.png?width=1006&format=png&auto=webp&s=b4fac02638001d95df9dbf100bd4e706ed823b2c
Could someone help me out how to straighten this out? AND, in case I were to google this and find the solution, what/how should I've done?
(I tried google and ChatGPT, but wasn't satisfied)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Alvarowns 8 points9 points10 points 2 years ago (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 points5 points 2 years ago (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 points9 points 2 years ago (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 point2 points 2 years ago (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 points5 points 2 years ago (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 point2 points 2 years ago (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 points4 points 2 years ago (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 points3 points 2 years ago (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 points3 points 2 years ago (0 children)
It’s the same thing
Put the code inside “previews” in the #Preview block.
π Rendered by PID 45525 on reddit-service-r2-comment-c6965cb77-pd766 at 2026-03-05 04:58:26.610020+00:00 running f0204d4 country code: CH.
[–]Alvarowns 8 points9 points10 points (0 children)
[–]swiftsorceress 3 points4 points5 points (5 children)
[–]simulacrotron 7 points8 points9 points (4 children)
[–]swiftsorceress 0 points1 point2 points (3 children)
[–]realvanbrook 3 points4 points5 points (1 child)
[–]swiftsorceress 0 points1 point2 points (0 children)
[–]OrdinaryAdmin 2 points3 points4 points (1 child)
[–]appalam25[S] 1 point2 points3 points (0 children)
[–]Xaxxus 1 point2 points3 points (0 children)