Type annotations

Type annotations let us be explicit about what data types we want, and look like this

let surName: String = "Park"
var score: Int = 1
var score1: Double = 3.1415
var isAuthenticated: Bool = true

we can put type annotaions for Array, dictionary, and set.

var albuns: [String] = ["Red", "Fearless"]
var userId: [String: String] = ["id": "@gmail.com"]
var userPassword: [String: Int] = ["id": 0000]
var books: Set<String> = Set(["Foundation", "Girl", "Eye"])


Create an Empty Array of Strings

Type annotation isn’t required, but we still need to know that an array of strings is written as [String] so that we can make the thing.

var teams: [String] = [String]()

Assign an empty array to it

var cities: [String] = []
var clues = [String]()

we can create a constant that doesn’t have a value just yet, later on provide that value, and Swift will ensure we don’t accidentally use it until a value is present. it will also ensure that we only ever set the value once, so that it remains constant. we are saying ‘username’ will contain a string at some point, and we provide a value before using it.

let username: String
username = "id"
print(username)


Checkpoint 2

Create an array of strings, then write some code that prints the number of items in the array and also the number of unique items in the array.

var check = ["voucher", "age", "Cotton", "feedback", "inject", "inject"]
print(check.count)
print(check)

var check1 = (check)
print(check1.count)