Today I started learning SwiftUI using Paul Hudson's 100 Days of SwiftUI challenge.
I have attempted completing programming courses several times without any success. However, this time I'll be sticking with Paul's suggestion that posting one's progress can help get more motivation to scale through tough times.
I set out to learn SwiftUI, but Paul stated that
"You can’t build software without having a programming language, so behind SwiftUI lies Swift itself: a powerful, flexible, and modern programming language that you’ll use for all your SwiftUI apps."
I am very optimistic I'll complete this challenge with this new approach.
Please find below a summary of my jottings on the first day of learning about Swift
- Variables - It is used for storing program data. Its value can be changed in programs over time. Variables are created using the var keyword. Please note that Swift is a type-safe language, that is, every variable must be of one specific type.
// Declaring a variable var language = "Objective-C" // Changing the value of the variable // You don't need to use "var" since the variable is already declared language = "Swift"
- Constants - When you need to set up a value once and never have to change it - you’ll use a constant. Constants are created using the let keyword. Please note that it’s preferable to use constants as often as possible.
// Declaring a constant // If you attempt to change the value of a constant, you'll get a // "Cannot assign to value: 'constant_name' is a 'let' constant" error let goldenRatio = 1.618
- Type inference - Swift is able to infer the type of a variable based on how it was created.
// Swift automatically detects this is a String data type var club = "Arsenal" // Swift automatically detects this is a Constant data type let gaussConstant = 0.835
- Type annotations - Although Swift is able to infer the type of a variable, however, developers can specify the type of a variable themselves.
// Inform Swift this is a String data type var club : String = "Arsenal" // Inform Swift this is a Constant data type let gaussConstant : Constant = 0.835
- Integers - Its a data type used to store whole numbers. Please note that Swift also uses underscores as thousands separators which makes numbers in its millions easier to read. This doesn't change the value of the number itself.
let yearOfBirth = 1991 // You can explicitly declare its data type var yearOfBirth : Int = 1991 // Thousand seperator feature var amount = 500_000_000
- Doubles - Double in Swift actually means "double-precision floating-point number". Its a data type used to store fractional number.
let total = 35_467.89
- Booleans - Its a data type used to store true or false.
let isValid = true
- Strings - Its a data type used to store string of letters. It starts and ends with double quotes.
let message = "Hello, Africa!"
- String Interpolation - This is the ability to place variables, constants in strings to make it more useful. To place the variable/constant, you'll use a backslash and a bracket containing the variable/constant.
var balance = 7_000_000 var accountBalance = "Your account balance is \(balance)"
Thanks for reading🙏🏿.
You can find me on Twitter @RealKennyEdward
Top comments (0)