我想運行下面的代碼,但無法轉換rest.value而沒有前面的「可選」。以下是代碼試圖解決這個問題時,我得到:無法將anyObject轉換爲字符串
//for Withdrawl children
transRef.child("Withdraw").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
//creates enumerator of the snapshot children for
let enumerator = snapshot.children
while let rest = enumerator.nextObject() as? FIRDataSnapshot {
let curString = (rest.value) as! String
self.anArray.append(curString)
//printing the rest.value to make sure there are children to iterate through
print(rest.value)
}
self.tableView.reloadData() //<<<<<<<<<<<< RELOAD TABLEVIEW
})
這是我收到的錯誤:Could not cast value of type '__NSCFNumber' (0x10d068368) to 'NSString'
可能的複製[iOS Swift:無法將值類型'\ _ \ _ NSCFNumber'轉換爲'NSString'](http://stackoverflow.com/questions/40798220/ios-swift-could-not-cast-value-type-nscfnumber-到的NSString) – Sasang