How to connect pair to arrays to contain the same index?

I am developing a quiz app for iOS and I keep the questions in an array and the answers in another array. So far I have been able to have a label display a random question from the question array with arc4random. However when I try to set up buttons to display random answer choices they don’t match the assigned question. For example, the question at index = 0 in the question array goes with the array of answers at index = 0 in the answers array and so. How can I make it to where whenever a random question is generated the correct answers display with (in other words how do I make sure they both always have a matching index that is pulled by the arc4random method or whatever method)?

Here is some of my code:

//random question generation function
func randomQuestion() {
    index = Int(arc4random_uniform(UInt32(questions.count)))
    questionLabel.text = questions[index]

let questions = ["Who is Thor's half brother?", "What is the name of Thor's hammer?", "What is Thor's father name?"]

//Each correct answer is placed at index 0 (right answers are Atum, Mjolinr, & Odin)
var answers = [["Atum", "Loki", "Red Norvell", "Kevin Masterson"], ["Mjolinr", "Uru", "Stormbreaker", "Odin's Staff"], ["Odin, "Sif", "Heimdall", "Balder"]]

//This variable is used in a later function that helps randomize wear the correct answer will be placed randomly from a set of buttons
var rightAnswerBox:UInt32 = 0

IBAction func buttonAction(_ sender: AnyObject) {

if (sender.tag == Int(rightAnswerBox)) {

print ("Correct!")

else {

print ("Wrong!")


    if (currentQuestion != questions.count)

override func viewDidAppear(_ animated: Bool)


//function that displays new question
func newQuestion()

//countdown timer section


rightAnswerBox = arc4random_uniform(4)+1

//create a button
var button:UIButton = UIButton()

var x = 1

for index in 1...4
    //creat a button
    button = view.viewWithTag(index) as! UIButton

    if (index == Int(rightAnswerBox))
        button.setTitle(answers[currentQuestion][0], for: .normal)


    else {

        button.setTitle(answers[currentQuestion][x], for: .normal)

    x += 1

currentQuestion += 1


Use Dictionary to assign the answers to the appropriate questions.

let QADictionary = ["Who is Thor's half brother?" : ["Atum", "Loki", "Red Norvell", "Kevin Masterson"],"What is the name of Thor's hammer?": ["Mjolinr", "Uru", "Stormbreaker", "Odin's Staff"], "What is Thor's father name?" : ["Odin", "Sif", "Heimdall", "Balder"] ]

//Get question list
let questionsList = Array(QADictionary.keys)
// Random question index
let index = Int(arc4random_uniform(UInt32(questionsList.count)))
// Fetch question from list
let question = questionsList[index]
// Assign to label
questionLabel.text = question

//Get the answer for the randomly chosen question. Because you question is the `Key` for the dictionary.
let answer = QADictionary[question]

@Saurabh Prajapati ‘s suggestion is correct for your requirement.

Step1: First store your questions and answers in a dictionary.

Step2: Make an array with the key of your dictionary as follows.

For example your dictionary name is quizDic.

 var questionsArray = quizDic.keys.Array

Step3: Find your questionsArray count and pass that value to the random generated function.

Step4: Then Access you correct answer from quizDic based on randomly selected key from the questionsArray.