What's the Best Way to Shuffle an NSMutableArray?

后端 未结 12 1723
太阳男子
太阳男子 2020-11-21 11:53

If you have an NSMutableArray, how do you shuffle the elements randomly?

(I have my own answer for this, which is posted below, but I\'m new to Cocoa an

12条回答
  •  自闭症患者
    2020-11-21 12:07

    If you import GameplayKit, there is a shuffled API:

    https://developer.apple.com/reference/foundation/nsarray/1640855-shuffled

    let shuffledArray = array.shuffled()
    

提交回复
热议问题