【发布时间】:2016-04-21 13:23:56
【问题描述】:
我正在尝试使用他们的用户名列出我在 Firebase 中的所有用户。
我的问题是我正在尝试创建一个包含所有用户的数组。
import UIKit
import Firebase
var memberRef = Firebase(url: "\(BASE_URL)/users")
//var currentUser = DataService.dataService.USER_REF.authData.uid
var currentUsers: [String] = [String]()
class dataTableView: UITableViewController
{
override func viewDidLoad()
{
loadUsers()
}
func loadUsers()
{
// Create a listener for the delta additions to animate new items as they're added
memberRef.observeEventType(.ChildAdded, withBlock: { (snap: FDataSnapshot!) in
print(currentUsers)
// Add the new user to the local array
currentUsers.append(snap.value as! String)
// Get the index of the current row
let row = currentUsers.count - 1
// Create an NSIndexPath for the row
let indexPath = NSIndexPath(forRow: row, inSection: 0)
// Insert the row for the table with an animation
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Top)
})
}
但是我得到错误不能将 NSDictionary 类型的值转换为 NSString。
【问题讨论】:
-
请将您的 Firebase 结构粘贴为文本而不是图片。您可以使用 Firebase 仪表板中的导出按钮来获取它。文本将使我们不必重新输入答案中的结构。
标签: swift firebase firebase-realtime-database