Your next career begins with
Save 50% off your seat in our next iOS Bootcamp. Limited time only. Sessions start April 3.
Your First iOS & SwiftUI App: An App from Scratch
Jan 11 2022 Swift 5.5, iOS 15, Xcode 13
Part 2: SwiftUI Data
15. Strings

Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
About this episode
Learn about a very important data type you’ll use in your iOS apps, which you can use to store a sequence of characters.
Instructors
Contributors
Instructor
Instructor
Illustrator
Video Editor
Over 300 content creators. Join our team.
Version history
iOS 15, Swift 5.5, Xcode 13 (Selected)
Jan 11 2022iOS 16, Swift 5.7, Xcode 14
Feb 13 2023iOS 14, Swift 5, Xcode 12
Dec 15 2020iOS 13, Swift 5, Xcode 11
Sep 3 2019iOS 12, Swift 4, Xcode 10
Jul 24 2018iOS 11, Swift 4, Xcode 9
Sep 19 2017iOS 10, Swift 3, Xcode 8
Nov 7 2016Swift 2
Sep 1 2015Leave a rating/review
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
This video Strings was last updated on Jan 11 2022
It’s time to tackle the next item on our programming to-do list: “Read the value of the slider after the user presses the Hit Me button.”
Before we start working on this, I want to tell you about a very important data type you’ll use in your iOS apps: Strings.
To create a String in Swift, you simply surround some text by quotes.
Behind the scenes, strings are just a sequence of characters. You can imagine them as a bunch of characters hanging on a piece of string, like you see here.
Strings in Swift have a cool feature called string interpolation. That’s just a fancy way of saying that you can put placeholder values inside your string, that are replaced dynamically by code when the app runs.
Imagine you have a string where you want to put a dynamic value inside at runtime. For example, maybe you want to say Hello, and then the name of the user of the app.
To do this, wherever you want the value to appear in your string, you put a backslash, and two parenthesis. Inside the parenthesis, you put some code that evaluates to the value to display.
In this example, if name is set to Ray, at runtime the string will become “Hello, Ray”.
Let’s try this out by making our app print out the value of the slider, inside a string.
Change alert text to:
message: Text("The slider's value is \(self.sliderValue)."),
Build & run.
We’re now printing the value of the slider, but currently it’s displaying the value with an annoying level of precision. It would be nice to print this out as a whole number - also known as an Integer - rather than having decimal points. How do we fix this?
Well, you’ll find out in the next episode.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development — plans start at just $19.99/month! Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.
Learn more