在Swift 4中改组多选数组

时间:2018-05-25 21:20:58

标签: arrays swift4 shuffle

有人可以解释我如何改组包含多个项目的数组,如下所示:

var answers = [["A","B","C"], ["D","E","F"], ["G","H","I"], ["J","K","L"]]

我知道要改组一个简单的数组,但这个更复杂,我尝试了很多方法,没有任何作用。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

关于洗牌阵列有很多关于SO的问题。我个人使用的解决方案是GameplayKit提供的功能。你不需要编写游戏来使用它:

import GameplayKit

var answers = [["A","B","C"], ["D","E","F"], ["G","H","I"], ["J","K","L"]]
answers = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: answers) as! [[String]]