I'm trying to order by timestamp, named 'Alpha' as a Field, but I'm hitting an error: "Unexpectedly found nil while unwrapping an optional value". I've tried following the Docs, but am still not quite sure where I'm going wrong. Any help would be greatly appreciated.
I detail my code below:
func getFollowingPosts() {
db.collection("iAmFollowing").document(currentUserID!).getDocument { (document, error) in
if error != nil {
print("ERROR")
} else {
if let document = document, document.exists {
let followedUID = document.get("uid") as? String
self.db.collection("posts")
.order(by: "Alpha")
.whereField("uid", isEqualTo: followedUID!).getDocuments(completion: { (documents, error) in
for documents in documents!.documents {
let title = documents.get("Title") as! String
let content = documents.get("Content") as! String
let username = documents.get("username") as! String
let postID = documents.get("postID")
let counter = documents.get("counter")
self.titleArray.append(title)
self.contentArray.append(content)
self.usernameArray.append(username)
self.postIDArray.append(postID as! Int)
self.effectsLabelArray.append(counter as! Int)
print(self.titleArray)
self.tableView.reloadData()
}
}
)}
}
}
}