Introduction to Swift

Apr 24 2024 · Swift 5.10, iOS 17, Xcode 15

Lesson 04: Problem Solving

Crashing Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Writing 100 percent bug-free code is a myth. There’s no shame in having some bugs in your code, but it’s important to have them under control and not have too many of them that give your users a negative experience.

calculateSum(minValue: -10, maxValue: 10)
calculateSum(minValue: 10, maxValue: -10)
calculateSum(minValue: 1, maxValue: 10)
calculateSum(minValue: 0, maxValue: Int.max)
var sum: Double = 0
func calculateSum(minValue: Int, maxValue: Int) -> Double {
let doubleVal1 = Double(minValue)
let doubleVal2 = Double(maxValue)
sum = (doubleVal1 + doubleVal2) / 2.0
sum *= doubleVal2 - doubleVal1 + 1.0
See forum comments
Cinema mode Download course materials from Github
Previous: Guarding Against Bad Input Next: Conclusion