Introduction to Swift

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

Lesson 01: Swift Basics

Arrays 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

In this demo, you’ll write Swift code to calculate the first few digits in the Fibonacci sequence and store them in an array.

var fibonacciSeries: [Int] = []
let fibonacci_0 = 0
fibonacciSeries.append(fibonacci_0)
print(fibonacciSeries[1])
let fibonacci_1 = 1
fibonacciSeries.append(fibonacci_1)
let fibonacci_2 = fibonacci_0 + fibonacci_1
fibonacciSeries.append(fibonacci_2)
let fibonacci_3 = fibonacci_1 + fibonacci_2
fibonacciSeries.append(fibonacci_3)

let fibonacci_4 = fibonacci_2 + fibonacci_3
fibonacciSeries.append(fibonacci_4)
print(fibonacciSeries[0])
print(fibonacciSeries[1])
print(fibonacciSeries[2])
print(fibonacciSeries[3])
print(fibonacciSeries[4])
print(fibonacciSeries)
See forum comments
Cinema mode Download course materials from Github
Previous: Arrays Next: Conclusion