The problem is that mentions[0...3] returns an ArraySlice<String>, not an Array<String>. Therefore you could first use the Array(_:) initialiser in order to convert the slice into an array:

let first3Elements : [String] // An Array of up to the first 3 elements.
if mentions.count >= 3 {
    first3Elements = Array(mentions[0 ..< 3])
} else {
    first3Elements = mentions
}

Or if you want to use an ArraySlice (they are useful for intermediate computations, as they present a 'view' onto the original array, but are not designed for long term storage), you could subscript mentions with the full range of indices in your else:

let slice : ArraySlice<String> // An ArraySlice of up to the first 3 elements
if mentions.count >= 3 {
    slice = mentions[0 ..< 3]
} else {
    slice = mentions[mentions.indices] // in Swift 4: slice = mentions[...]
}

Although the simplest solution by far would be just to use the prefix(_:) method, which will return an ArraySlice of the first n elements, or a slice of the entire array if n exceeds the array count:

let slice = mentions.prefix(3) // ArraySlice of up to the first 3 elements
Answer from Hamish on Stack Overflow
Discussions

Why does Swift have an ArraySlice type that is not interchangeable with the Array type? Isn't an array slice an optimization that is best hidden from the programmer?

Swift has taken the approach where a sliced collection is simple a view into the storage of the original collection, rather than eagerly copying its elements into a new Array. The reason to have a specific ArraySlice type is so you are aware of the memory management around the contents of the original array – the slice is holding a strong reference to it, so it will stay alive even after other references have disappeared. This gives you control over when a copy occurs so you can optimise performance and memory usage.

This is explained further by Ben Cohen in What's New in Swift - WWDC 17 at 35 minutes in, which covers slicing strings but also applies to arrays and other collections.

More on reddit.com
🌐 r/swift
27
19
August 8, 2017
Functions that accept arrays or array slices - Using Swift - Swift Forums
All was well until I needed to implement various multiplication algorithms. In particular, Karatsuba and Toom Cook multiplication. Both of these algorithms are divide and conquer based with Karatsuba breaking down the array into two slices and Toom Cook 3 or more slices. In Swift... More on forums.swift.org
🌐 forums.swift.org
1
April 29, 2022
[Rant] Indexing into ArraySlice - Using Swift - Swift Forums
Here is an anecdote, can you guess ... Output: I believe, shared indexing is performance optimization at the expense of usability. A slice looks in every way just like an array, except for indexing. I have to be very careful with indexing when there are slices involved. But ... More on forums.swift.org
🌐 forums.swift.org
5
May 20, 2018
What is the purpose of Swift's ArraySlice or SubArray, other than to avoid a performance penalty of copying?
Swift actually has some great documentation about how and why Array is implemented as it is. More on reddit.com
🌐 r/swift
9
2
June 6, 2017
🌐
Swift by Sundell
swiftbysundell.com › articles › slicing-swift-collections
Slicing Swift collections | Swift by Sundell
February 2, 2020 - In Swift, a slice is a special kind of collection that doesn’t actually store any elements of its own, but rather acts as a proxy (or view) to enable us access and work with a subset of another collection as a separate instance.
🌐
Swdevnotes
swdevnotes.com › swift › 2023 › arrayslice-with-range-operator-and-prefix-in-swift
ArraySlice with range operator and Prefix in Swift | Software Development Notes
January 1, 2023 - ArraySlice is used in Swift to return a view on a subset of a collection without the overhead of making a copy of the collection. The half-open range (..<) and closed range (...) operators are used to specify the index range to retrieve.
🌐
Medium
medium.com › appcoda-tutorials › understanding-the-arrayslice-3b4957b9d965
Understanding The ArraySlice in Swift | by Jimmy M Andersson | AppCoda Tutorials | Medium
June 9, 2019 - So the indices of our slice don’t range from 0 through 2, they actually range from 1 through 3! ... We solve it by using a technique that should (in an ideal world) be applied to every instance that can be subscripted. The ArraySlice class contains two properties named .startIndex and .endIndex, which gives us access to the offsets of the start and end of our slice.
🌐
Reddit
reddit.com › r/swift › why does swift have an arrayslice type that is not interchangeable with the array type? isn't an array slice an optimization that is best hidden from the programmer?
r/swift on Reddit: Why does Swift have an ArraySlice type that is not interchangeable with the Array type? Isn't an array slice an optimization that is best hidden from the programmer?
August 8, 2017 -

Update: Now that I have a better understanding of the issue from your comments below, I think this is premature optimization.

IMO, slicing by eagerly copying the elements into an Array type would be better as the default behavior. If you want something more efficient, then perhaps you could use an explicit ArraySlice type annotation, much like how you would use an explicit Character type annotation if you don't want a string.

🌐
W3Schools
w3schools.com › swift › swift_arrays_slices.asp
Swift Arrays - Slices
Tip: Slices keep original indices. Convert to Array for zero-based indices.
🌐
Swift Forums
forums.swift.org › using swift
Functions that accept arrays or array slices - Using Swift - Swift Forums
April 29, 2022 - All was well until I needed to implement various multiplication algorithms. In particular, Karatsuba and Toom Cook multiplication. Both of these algorithms are divide and conquer based with Karatsuba breaking down the array into two slices and Toom Cook 3 or more slices. In Swift...
Find elsewhere
🌐
GitHub
github.com › apple › swift › blob › main › stdlib › public › core › ArraySlice.swift
swift/stdlib/public/core/ArraySlice.swift at main
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors · // //===----------------------------------------------------------------------===// // // - `ArraySlice<Element>` presents an arbitrary subsequence of some · // contiguous sequence of `Element`s. // //===----------------------------------------------------------------------===// · /// A slice of an `Array`, `ContiguousArray`, or `ArraySlice` instance.
Author   swiftlang
🌐
Marcosantadev
marcosantadev.com › arrayslice-in-swift
ArraySlice In Swift - MarcoSantaDev
September 12, 2021 - For this reason, in example above, we have a compile error Cannot assign value of type 'ArraySlice<Int>' to type '[Int]'. We need a way to convert the ArraySlice object to Array. Fortunately, Swift allows us to cast the slice variable using the syntax Array(<slice_variable>).
🌐
Sarunw
sarunw.com › posts › how-to-get-first-n-elements-of-swift-array
How to get the first N elements of array in Swift | Sarunw
December 10, 2020 - Unlike an array, ArraySlice may have a nonzero startIndex and an endIndex that is not equal to count since it uses the same indices of the original array. The following example gets a slice of elements index 1 and 2 from the names array.
🌐
Swift Forums
forums.swift.org › using swift
[Rant] Indexing into ArraySlice - Using Swift - Swift Forums
May 20, 2018 - Here is an anecdote, can you guess the output? let abc = Array("abcdef") let some = abc[1...] some[1] == abc[1] some[1] == abc[2] let same = some.map{ $0 } same[1] == abc[1] same[1] == abc[2] Output: I believe, share…
🌐
Swdevnotes
swdevnotes.com › tags › arrayslice
arrayslice | Software Development Notes
Jan 1, 2023 · 6 min read · array arrayslice prefix · ... The Swift standard library provides an ArraySlice to work with a subset of a larger collection without the overhead of making a copy of the original collection.
🌐
Swift Package Index
swiftpackageindex.com › ml-explore › mlx-swift › 0.23.1 › documentation › mlx › indexing
mlx-swift Documentation – Swift Package Index
March 24, 2025 - This documentation is from a previous release and may not reflect the latest released version. View latest release documentation · This page requires JavaScript · Please turn on JavaScript in your browser and refresh the page to view its content · Last updated on 24 Mar 2025 · The Swift ...
🌐
TutorialsPoint
tutorialspoint.com › new-array-from-index-range-swift
New Array from Index Range Swift
In the end, we will convert the ArraySlice to an array using the Array initializer and print the result. import Foundation let numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] let startIndex = 3 // inclusive let endIndex = 8 // exclusive let slice = numbers[startIndex..<endIndex] // return an ArraySlice<Int> let newArray = Array(slice) // converts ArraySlice<Int> to [Int] print("Original array: \(numbers)") print("New array: \(newArray)")
🌐
Adrianrussell
adrianrussell.co.uk › blog › 2024 › 08 › 25 › swift-sequences-2
Adrian Russell - Sequences 2: Collections
The implementation for Sequence and Collection both return a new array which contains all the elements in reverse order. BidirectionalCollection instead returns a ReversedCollection object which wraps the original collection without having to allocate a new array of perform the reverse.
🌐
Mimo
mimo.org › glossary › swift › array
Swift Array: Syntax, Usage, and Examples
Manage collections easily with Swift arrays. Store, sort, filter, and map ordered values—perfect for building dynamic, data-driven app features.
🌐
Medium
medium.com › @mimicatcodes › array-and-arrayslice-in-swift-3-aaa6841d3119
Array and ArraySlice in Swift 3. In this post, we will learn how to grab… | by Luna An | Medium
June 15, 2017 - Array and ArraySlice in Swift 3 In this post, we will learn how to grab sub arrays out of arrays in Swift — and they are considered type ArraySlice. According to Apple, ArraySlice is: A slice of an …