EduFlow
Swift Essentials for iOS

Checkpoint: Swift the Language

Five questions on this section. Answer all of them, then see your score and why each answer is right or wrong.

Question 1 of 5

What does this print?

Swift
let input = "abc"
let amount = Int(input) ?? 0
print(amount + 5)
Question 2 of 5

Given func convert(_ amount: Decimal, to currency: String) -> Decimal, which call compiles?

Question 3 of 5

func monthlyAverage(_ amounts: [Decimal]) -> Decimal? must return nil for an empty array. Which first line is the idiomatic Swift way to handle that?

Question 4 of 5

You loop over expenses and want to count how many fall in each category, starting from an empty var counts: [String: Int] = [:]. Which line goes inside the loop?

Question 5 of 5

What is result?

Swift
let values = [5, 12, 30]
let result = values.filter { $0 > 10 }.map { $0 * 2 }.reduce(0, +)

5 questions unanswered