Day 1 of 100 Days of SwiftUI challenge
Tags: swift, swiftui, beginners
Published: 2020-01-15 13:43:27

#Introduction

Today I started learning [SwiftUI](https://developer.apple.com/xcode/swiftui/) using [Paul Hudson](https://twitter.com/twostraws)'s [100 Days of SwiftUI challenge](https://www.hackingwithswift.com/100/swiftui).

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.

#Why Swift?
I set out to learn SwiftUI, but Paul stated that <blockquote>*"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."*</blockquote>

I am very optimistic I'll complete this challenge with this new approach.

#Summary
Please find below a summary of my jottings on the first day of learning about Swift
<ul>
  <li>
    <strong>Variables</strong> - It is used for storing program data. 
    Its value can be changed in programs over time. Variables are created using the <strong>var</strong> keyword. <strong>Please note</strong> that Swift is a type-safe language, that is, every variable must be of one specific type.
  </li>
</ul>
``` swift
// 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" 
```

<ul>
  <li>
    <strong>Constants</strong> - 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 <strong>let</strong> keyword. <strong>Please note</strong> that it’s preferable to use constants as often as possible.
  </li>
</ul>
``` swift
// 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
```

<ul>
  <li>
    <strong>Type inference</strong> - Swift is able to infer the type of a variable based on how it was created.
  </li>
</ul>
``` swift
// 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
```

<ul>
  <li>
    <strong>Type annotations</strong> - Although Swift is able to infer the type of a variable, however, developers can specify the type of a variable themselves.
  </li>
</ul>
``` swift
// 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
```

<ul>
  <li>
    <strong>Integers</strong> - Its a data type used to store whole numbers. <strong>Please note</strong> that Swift also uses <strong>underscores </strong> as thousands separators which makes numbers in its millions easier to read. This doesn't change the value of the number itself.
  </li>
</ul>
``` swift
let yearOfBirth = 1991

// You can explicitly declare its data type
var yearOfBirth : Int = 1991

// Thousand seperator feature
var amount = 500_000_000
```

<ul>
  <li>
    <strong>Doubles</strong> - Double in Swift actually means "double-precision floating-point number". Its a data type used to store fractional number.
  </li>
</ul>
``` swift
let total = 35_467.89
```

<ul>
  <li>
    <strong>Booleans</strong> - Its a data type used to store true or false.
  </li>
</ul>
``` swift
let isValid = true
```

<ul>
  <li>
    <strong>Strings</strong> - Its a data type used to store string of letters. It starts and ends with double quotes.
  </li>
</ul>
``` swift
let message = "Hello, Africa!"
```

<ul>
  <li>
    <strong>String Interpolation</strong> - 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.
  </li>
</ul>
``` swift
var balance = 7_000_000
var accountBalance = "Your account balance is \(balance)"
```

Thanks for reading🙏🏿.

You can find me on Twitter [@RealKennyEdward](https://twitter.com/RealKennyEdward)