I have a function to get certain posts from Firebase
var posts = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
FIRDatabase.database().reference().child("Likes").child(self.loggedInUser!.uid).observe(.childAdded, with: { (snapshot) in
self.ID = snapshot.key
print(self.ID!)
})
loadData()
}
func loadData(){
FIRDatabase.database().reference().child("books").child(self.ID!).observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in
if let postsDictionary = snapshot .value as? [String: AnyObject] {
for post in postsDictionary {
self.posts.add(post.value)
}
self.SoldTableView.reloadData()
}})
}
Now I get an error on
FIRDatabase.database().reference().child("books").child(self.ID!).observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in
saying fatal error: unexpectedly found nil while unwrapping an Optional value