Introduction to Swift

Apr 24 2024 · Swift 5.10, iOS 17, Xcode 15

Lesson 01: Swift Basics

Strings Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this demo, you’ll use a playground to merge strings to create a custom greeting message that includes the user’s name. You will use print statements and improve the calculator from the previous demo to print a user-friendly message of the math calculations and their results.

let welcomeMessage_part1 = "Hello "
let username = "Raymond"
let welcomeMessage_part2 = ", it's good to see you today."
let message = welcomeMessage_part1 + username + welcomeMessage_part2
print(message)
print(message.count)
print(message.uppercased())
print(message.lowercased())
print(message.replacing("Hello", with: "Greetings"))
let message2 = "Hello \(username), it's good to see you today."
print(message2)
let int1 = 10
let int2 = 5
let intSum = int1 + int2

let intSubtract = int1 - int2

let intMultiply = int1 * int2

let intDivide = int1 / int2
print("Integer sum of \(int1) and \(int2) is: \(intSum)")
print("Integer subtraction of \(int1) and \(int2) is: \(intSubtract)")

print("Integer multiplication of \(int1) and \(int2) is: \(intMultiply)")

print("Integer division of \(int1) and \(int2) is: \(intDivide)")
let float1: Float = 11
let float2: Float = 6

let floatDivide = float1 / float2

let double1 = 11.0
let double2 = 6.0

let doubleDivide = double1 / double2
print("Floating-point division of \(float1) and \(float2) is: \(floatDivide)")

print("Double-precision floating-point division of \(double1) and \(double2) is: \(doubleDivide)")
See forum comments
Cinema mode Download course materials from Github
Previous: Strings Next: Arrays