Невозможно добавить значение типа '[UInt32]'
У меня есть массив чисел, которые были сгенерированы случайным образом, и затем я пытаюсь запросить у Firebase вопрос, равный значению по индексу [0] в массиве выбранных чисел. Проблема на данный момент в том, что я получаю ошибкуCannot subscript a value of type '[UInt32]'
, Постскриптум Я не очень опытен в быстром темпе, поэтому точные решения кода будут очень ценными! Я также прикрепил свою структуру Firebase ...
import UIKit
import Firebase
class QuestionViewController: UIViewController {
let ref = Firebase(url: "https://123test123.firebaseio.com/questions")
override func viewDidLoad() {
super.viewDidLoad()
// An empty array to hold the selected numbers
var selectedNumbers: [UInt32] = []
// A range of acceptable numbers
let randomNumberRange = 1...10
// How many numbers are needed?
let randomNumbersToChoose = 10
// Crash if asking for more numbers than are available in the range
assert(randomNumberRange.count >= randomNumbersToChoose, "Must have enough numbers to choose from!")
// Repeat this loop until all enough numbers have been selected
while selectedNumbers.count < randomNumbersToChoose {
// Pick a random number within the allowed range
let selectedNumber = arc4random_uniform(UInt32(randomNumberRange.endIndex - randomNumberRange.startIndex)) + UInt32(randomNumberRange.startIndex)
// If it's not already in the selected array, add it
if (selectedNumbers.indexOf(selectedNumber) == nil) {
selectedNumbers.append(selectedNumber)
}
}
// Print the result
print(selectedNumbers)
print(selectedNumbers)
let selectedNumberIndex: UInt32 = 2
ref.queryOrderedByChild("value").queryEqualToValue(selectedNumbers[0])
.observeEventType(.ChildAdded, withBlock: {
snapshot in
//Do something with the question
print(snapshot.key)
print(snapshot.value.valueForKey("question"))
})
}
@IBAction func truepressed(sender: AnyObject) {
}
@IBAction func falsePressed(sender: AnyObject) {
}
}
Данные JSON:
{
"question1" : {
"answer" : "Nohghpe",
"question" : "Do you know swift",
"value" : 1
},
"question10" : {
"answer" : "A fdsbit",
"question" : "Do you kndfggow firebase",
"value" : 10
},
"question2" : {
"answer" : "A bfhit",
"question" : "Dodhfg you know firebase",
"value" : 2
},
"question3" : {
"answer" : "A bsdit",
"question" : "Do you know firebsgdfase",
"value" : 3
},
"question4" : {
"answer" : "A vcxbit",
"question" : "Do yosgfdu know firebase",
"value" : 4
},
"question5" : {
"answer" : "A bivcxt",
"question" : "Do you kfghnow firebase",
"value" : 5
},
"question6" : {
"answer" : "A bxcvit",
"question" : "Do you know fnhirebase",
"value" : 6
},
"question7" : {
"answer" : "A bivxct",
"question" : "Do you sgdfknow firebase",
"value" : 7
},
"question8" : {
"answer" : "A bivcxt",
"question" : "Do you knsfdow firebase",
"value" : 8
},
"question9" : {
"answer" : "A bdsfit",
"question" : "Do you kdfgnow ffsdirebase",
"value" : 9
}
}