我正在使用Firebase和Xcode以及Swift 2.0的最新版本,我正在尝试从Firebase检索数据但由于某种原因,函数observeEventType
永远不会被调用。
我的Dataservice课程:
import Foundation
import Firebase
let URL_BASE = FIRDatabase.database().reference()
class DataSevice {
static let ds = DataSevice()
private var _REF_BASE = URL_BASE
private var _REF_POSTS = URL_BASE.child("posts")
private var _REF_USERS = URL_BASE.child("users")
var REF_BASE: FIRDatabaseReference{
return _REF_BASE
}
var REF_POSTS: FIRDatabaseReference{
return _REF_POSTS
}
var REF_USERS: FIRDatabaseReference{
return _REF_USERS
}
func createFirebaseUser(uid: String, user: Dictionary<String, String>){
REF_USERS.childByAppendingPath(uid).setValue(user)
}
}
我需要检索数据的FeedVC类:
import UIKit
import Firebase
class FeedVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
var posts = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
DataSevice.ds.REF_POSTS.observeEventType(FIRDataEventType.Value, withBlock: { snapshot in
//this is not being called
})
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let post = posts[indexPath.row]
print(post.postCaption)
return tableView.dequeueReusableCellWithIdentifier("PostCell") as! PostCell
}
}