

For example, we could give our text a white foreground color and a blue background color like this: Text("Hello, world!") You can also control the background color of the text by adding another modifier. That will give the text a large font and a blue color. There are lots of these built right in to SwiftUI, and you’ll often find yourself using several at once to get exactly the right effect.įor example, try changing your text to include these modifiers below: Text("Hello, world!") We can customize the way our text looks by adding modifiers.
#XCODE TUTORIAL CODE#
We’re going to be writing a lot more code in there over the course of this tutorial, but first I want to spend a few minutes just noodling around with the basics so you have a better grasp of what’s going on. Finally, it says the UI we want to show is the text “Hello, world!”.That means our ContentView will show other pieces of UI inside. It says the body of this view – the thing that’s actually shown on the screen – will return some kind of SwiftUI view.You’ll create lots of views in your apps, but each one needs its own unique name. It creates a new piece of UI, known as a view in SwiftUI, that is called ContentView.Swift is the programming language we use to build our apps, but SwiftUI is a set of tools that gives us buttons, images, and other common user interface elements. It tells Swift to bring in the SwiftUI framework.

I expect the starter code will change over time, but that’s okay because I want you to delete almost all of it – leave only this behind: import SwiftUIĪs you delete parts, you’ll see the preview on the right change immediately – it really is live, and later on you’ll see it’s interactive too.

Go ahead and tap your new playground to open it for editing, and you’ll see Playgrounds splits into two parts: on the left is some simple Swift code to get us started, and on the right is a live preview that shows your actual code running.
#XCODE TUTORIAL HOW TO#
This will be called My App by default, and it will be given a random icon – I’ll show you how to change those later. To get started, press the “App” button under “Get a Playground” to create a new project. Save 50% on all our books and bundles! First steps SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
