Learn fundamental Swift concepts with visual examples using SwiftUI. Contact Amos on Twitter: @amos_gyamfi. Each Swift concept explained and illustrated with tangible examples.
import SwiftUI
/*
Type aliases define an alternative name for an existing type. You define type aliases with the typealias keyword.
Type aliases are useful when you want to refer to an existing type by a name thatβs contextually more appropriate.
*/
struct TypeAliases: View {
typealias Emoji = String
let smiley: Emoji = "π"
let winkingFace: Emoji = "π"
let moneyFace: Emoji = "π€"
let π: Emoji = "Revolving Hearts"
var body: some View {
List {
Text("Smiley face: \(smiley)")
Text("Winking face: \(winkingFace)")
Text("Money face: \(moneyFace)")
Text(π)
}
}
}
struct TypeAliases_Previews: PreviewProvider {
static var previews: some View {
TypeAliases()
.preferredColorScheme(.dark)
}
}
Swift alows you to name variables and constants using characters, including Unicode. CharacterConstantVariableNames.swift