过去一个月我运行了这段代码,很好。我不相信我改变了应该影响它的任何东西,但现在当我运行它时,我得到一个错误,说firebase不接受这种对象。这是我的代码:
var postId = ""
func UploadPost(){
let FirstName = LoggedIn.User["First Name"] as! String
let LastName = LoggedIn.User["Last Name"] as! String
let posterId = LoggedIn.User["UserID"] as! String
let Name = FirstName + " " + LastName
let Epoch = Date().timeIntervalSince1970
let Title = PostTitle.text
let Posting = Post.text
self.postId = UUID().uuidString
if(Title != nil && Posting != nil){
let Post = [
"Post": Posting!,
"PostTitle": Title!,
"Poster": Name,
"Epoch": Epoch,
"Username": self.user,
"PostId": self.postId,
"PosterId": posterId
] as [String : Any]
PostData(newPostData: Post){(success, error) in
guard success else{
let BadPostRequest = Banner.ErrorBanner(errorTitle: "Could not write post.")
BadPostRequest.backgroundColor = UIColor.black.withAlphaComponent(1)
self.view.addSubview(BadPostRequest)
GenericTools.Logger(data: "\n Could not write post: \(error!)")
return
}
self.activityIndicator.stopAnimating();
UIApplication.shared.endIgnoringInteractionEvents();
self.dismiss(animated: true, completion: nil)
}
}
}
func PostData(newPostData: Dictionary<String, Any>, completion: @escaping (Bool, Error?) -> Void){
let v = postId
Database.database().reference().child("Forum").child(self.postId).setValue(newPostData){ error in
completion(false, error)
}
Database.database().reference().child("Forum/ForumIds").child(self.postId).setValue(self.postId){ error in
completion(false, error)
}
completion(true, nil)
}
错误:
*** Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(nodeFrom:priority:) Cannot store object of type _SwiftValue at . Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'
*** First throw call stack:
(0x184777d38 0x183c8c528 0x104ed013c 0x104ecf6c4 0x104ecf5f8 0x104ecf4e4 0x104ecf80c 0x104ecf6c4 0x104ecf5f8 0x104eb013c 0x104eaffd0 0x104db0dfc 0x104db02b0 0x104dac4e4 0x104dac678 0x18dbbc20c 0x18dbbc18c 0x18dba6f4c 0x18dbbba80 0x18dbbb5a0 0x18dbb6a70 0x18db88078 0x18e4c7f98 0x18e4ca408 0x18e4c3574 0x184720358 0x1847202d8 0x18471fb60 0x18471d738 0x18463e2d8 0x1864cff84 0x18dbeb880 0x104d7f734 0x18416256c)
libc++abi.dylib: terminating with uncaught exception of type NSException