如何从一系列4个问题中获得2个问题!迅速

时间:2016-09-12 04:11:19

标签: ios arrays swift random arc4random

如何设置我的随机功能只能得到2个结果。我只希望每个阵列得到2个问题而不是4个问题。 random()arc4random()?不确定哪个更好或这两种方法有什么区别!这是一种不同的情况,因为我在我的问题数组中使用了一个结构。

struct Question {
var question: String!
var answers: [String]
var answer: Int!
var img: UIImage!
var info: String!

}
//Here is my viewDidLoad
override func viewDidLoad() {
    super.viewDidLoad()
questions = [

        Question(
            question: "How old it was Steve Jobs in 2009?",
            answers: ["10","30","19","20    "],
            answer: 3,
            img: UIImage.self(named: "steve"),
            info: "Steve"
                ),]//....Here is more code with other questions
}

var questions = [Question]()//my array with the questions
var questionNumber = Int()

private func pickingRandomQuestion() {
    let numberQuestion = questions.count

if numberQuestion > 0{
    questionNumber = random() % questions.count//I only want to get  2 questions not the entire array of questions.
else {
NSLog("Done!")
}

0 个答案:

没有答案