Based on the compile error you are getting, I would assume that if you tried to press option and click on shuffledArray, probably, it would be of type [[Any]] (depends on how you are declaring it). If you know that the element should be a String, you could cast it as follows:
if let qLabelText = shuffledArray[0][1] as? String {
qlabel.text = qLabelText
}
But
I would note that:
if you are pretty sure that shuffledArray should be an array of strings array, then you should -somehow- declare it [[String]] instead, thus there is no need to cast the element as string.
However, for such a case, creating your own custom Model for such a case (template) might be a better choice of doing it as a 2D array.
For instance:
struct QuestionModel {
var number: String
var content: String
var answer1: String
var answer2: String
var answer3: String
var answer4: String
var correctAnswer: String
}
Definitely, the structure of declaring the model is based on your requirement and may not be necessary to clone it as is.
You could declare your question as:
let question1 = QuestionModel(number: "3", content: "Who invented the telephone?", answer1: "Rogers", answer2: "Virgin Mobile", answer3: "Graham Bell", answer4: "Nikola Tesla", correctAnswer: "0")
Thus shuffledArray would be an array of QuestionModel ([QuestionModel]) instead of [[String]].
Now, you could write your newQ function as:
func newQ() {
let queestion1 = shuffledArray[0]
qlabel.text = question1.content
button1.setTitle(question1.answer1, for: .normal)
button2.setTitle(question1.answer2, for: .normal)
button3.setTitle(question1.answer3, for: .normal)
button4.setTitle(question1.answer4, for: .normal)
}
Following the above approach would be more expressive and easy to work with.
shuffledArray?String(describing: shuffledArray[0][2])should work too. Exactly as you did forqLabelString(describing:)for user-facing content. Ever.