:
/** Setting up the Data **/
var genresLabelIndex = ["Fiction", "Poetry", "NonFiction", "Science"]
var fiction = [InformationForFeed]()
var poetry = [InformationForFeed]()
var nonFiction = [InformationForFeed]()
var science = [InformationForFeed]()
var allGenresData = [[Any]]()
func getData() {
for genre in genresLabelIndex {
let dbReference = FIRDatabase.database().reference().child("genres").child(genre)
let query = dbReference.queryOrderedByKey().queryLimited(toFirst: 3)
query.observeSingleEvent(of: .value, with: { (snapshot : FIRDataSnapshot) in
if snapshot.childrenCount > 0 {
for snap in snapshot.children.allObjects as! [FIRDataSnapshot] {
let item = snap.value as! Dictionary<String,AnyObject?>
let data = InformationForFeed(dictionary: item as Dictionary<String,AnyObject>)
for i in (self.allGenresData) {
self.allGenresData[i].append(data)
}
}
} else {
print("This snap shot doesnt have any data")
}
})
}
print(allGenresData)
}
私のエラーは、私は次のことをやっている私のInit内の行self.allGenresData[i].append(data)
()であります
これを試してください:
var dataArray = [InformationForFeed]()
let data = InformationForFeed(dictionary: item as Dictionary<String,AnyObject>)
dataArray.append(data)
for i in (self.allGenresData) {
self.allGenresData[i].append(dataArray)
}
* [[InformationForFeed]]
にInformationForFeed
を入れようとしています。
エラーメッセージはどうなりますか? – paper1111
"Any型の値にAny型のインデックスを添字することはできません" – AndrewS