Tsallaka zuwa abun ciki
Justice Tech School

Slices and Ranges

A slice is a view of part of an array. Convert with Array().

Example
let a = [10, 20, 30, 40, 50]
let s = a[1...3]
print(s, Array(s), s.first!)
print(a.prefix(2), a.suffix(2), a.dropFirst())

Exercise

Copy a slice.

(slice)

Quiz Test

What does prefix(2) give?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.