This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
This tutorial belongs to the Swift series
Suppose you have an array in Swift, like this:
let items = [1, 2, 3]
and you want to get a random number out of it.
The Array data type provides the randomElement()
function that returns an Element?
:
let item = items.randomElement()
This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

flaviocopes.com | Sciencx (2021-06-15T05:00:00+00:00) Swift, how to get a random item from an array. Retrieved from https://www.scien.cx/2021/06/15/swift-how-to-get-a-random-item-from-an-array/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.