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
🌐
W3Schools
w3schools.com › swift › swift_arrays_slices.asp
Swift Arrays - Slices
Networking Persistence Persistence ... Signing & Distribution TestFlight & App Store Ship Your First App ... Use ranges to create slices of arrays....
🌐
Medium
medium.com › appcoda-tutorials › understanding-the-arrayslice-3b4957b9d965
Understanding The ArraySlice in Swift | by Jimmy M Andersson | AppCoda Tutorials | Medium
June 9, 2019 - Before we dive into some code, let’s take a moment to recognize that an instance of ArraySlice will actually increase the reference counter for the underlying storage of the array. Because of this, it is never a good idea to store a slice for longer than you absolutely need to, since it will keep the whole memory space from being deallocated if the array is deallocated before our array slice (that means the whole memory space, not just a few elements that the slice may be referencing).
🌐
Swift by Sundell
swiftbysundell.com › articles › slicing-swift-collections
Slicing Swift collections | Swift by Sundell
At first glance, it might seem like firstFive would have the same type as numbers, which is Array<Int>, but it actually doesn’t. In fact, what we’ve done above is to create a slice, in this case of type ArraySlice<Int>.
🌐
DZone
dzone.com › data engineering › data › arrayslice in swift
ArraySlice in Swift
October 11, 2017 - It’s very powerful and allows us to perform the same array operations on a slice like append, map and so on. In this article, we will see how to create it and some internal behaviors to avoid troubles. Happy reading! Before using an ArraySlice, we must understand how to create it. Swift provides ...
🌐
Swift Forums
forums.swift.org › using swift
Functions that accept arrays or array slices - Using Swift - Swift Forums
April 29, 2022 - I am working on a Big Integer package with emphasis on performance. My current design follows what most others have done, i.e. the Big Integer is a UInt64 array with functions contained in a Uint64 array extension. All…
🌐
Marcosantadev
marcosantadev.com › arrayslice-in-swift
ArraySlice In Swift - MarcoSantaDev
September 12, 2021 - Apple describes ArraySlice as “Views onto Arrays”. It means that an ArraySlice is an object which represents a subsequence of its array. It’s very powerful and allows us to perform the same array operations on a slice ...
🌐
Swdevnotes
swdevnotes.com › swift › 2023 › arrayslice-with-range-operator-and-prefix-in-swift
ArraySlice with range operator and Prefix in Swift | Software Development Notes
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.
Find elsewhere
🌐
GitHub
github.com › apple › swift › blob › main › stdlib › public › core › ArraySlice.swift
swift/stdlib/public/core/ArraySlice.swift at main · swiftlang/swift
// 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
🌐
Medium
medium.com › @marcosantadev › arrayslice-in-swift-4e18522ab4e4
ArraySlice In Swift. Original link… | by Marco Santarossa | Medium
October 9, 2017 - It's very powerful and allows us to perform the same array operations on a slice like append, map and so on. In this article, we will see how to create it and some internal behaviors to avoid troubles. Happy Reading! ... Before using an ArraySlice, we must understand how to create it. Swift ...
🌐
Swift Forums
forums.swift.org › evolution › discussion
Slicing should return Array by default rather than the confusing and error-prone ArraySlice - Discussion - Swift Forums
September 12, 2018 - ArraySlice is confusing and error-prone since indexing doesn't necessarily start at zero and many functions require arrays rather than slices as parameters. ArraySlice is also a form of premature optimization. IMO, it would be better for slicing to return an Array.
🌐
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 …
🌐
Swift Forums
forums.swift.org › using swift
How to get the base array from an `ArraySlice`? - Using Swift - Swift Forums
September 1, 2021 - Slice and Substring have a convenient base property, which is useful for getting access to the whole collection, but ArraySlice seems to have this functionality omitted. Is this intentional? Is it possible to get the who…
🌐
Objc
talk.objc.io › episodes › S01E32-array-arrayslice-collection
Array, ArraySlice & Collection - Swift Talk - objc.io
We show how to use the Collection protocol to make an extension available not just on array, but on all collections.
🌐
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…
🌐
Hacking with Swift
hackingwithswift.com › example-code › language › how-to-split-an-array-into-chunks
How to split an array into chunks - free Swift example code and tips
May 28, 2019 - extension Array { func chunked(into size: Int) -> [[Element]] { return stride(from: 0, to: count, by: size).map { Array(self[$0 ..< Swift.min($0 + size, count)]) } } }