When I want to upload something to the database but I got fatal error: unexpectedly found a nil while unwrapping an Optional value log. I found that currentUser = some but email, password, uid etc which are inside the currentUser are nil. I also found a EXC_BAD_INSTRUCTION here
func savePost(){
var text: String!
if let postName = postName.text {
text = postName
}
// The EXC_BAD_INSTRUCTION on the line of code below
let newPost = Posts(postName: text, username: self.currentUser.username, postId: NSUUID().uuidString, postDate: (NSDate().timeIntervalSince1970 as NSNumber), postType: "TEXT", uid: self.currentUser.uid, tutUrl: url)
let postRef = self.dataBaseRef.child("tuts").childByAutoId()
postRef.setValue(newPost.toAnyObject(), withCompletionBlock: { (error, ref) in
/ if error == nil {
self.navigationController!.popToRootViewController(animated: true)
}else {
print(error!.localizedDescription)
}*/
})
}
I am using Firebase and Swift. Please help. Thanks