此代码负责在登录用户的自动生成密钥下上传文本和帖子的时间,该密钥位于第一行的函数didtappost中
@IBOutlet weak var post: UIButton!
@IBOutlet weak var newpost: UITextView!
var databaseref = FIRDatabase.database().reference()
var loggedinuser : AnyObject?
override func viewDidLoad()
{
super.viewDidLoad()
self.loggedinuser = FIRAuth.auth()?.currentUser
newpost.textContainerInset = UIEdgeInsetsMake(30, 20, 20, 20)
newpost.text = "what is new?"
newpost.textColor = UIColor.lightGray
}
@IBAction func didtapcancel(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
func textFieldShouldReturn(_ textfield: UITextField) -> Bool {
textfield.resignFirstResponder()
return false
}
@IBAction func didtappost(_ sender: Any) {
if(newpost.text.characters.count>0)
{
let key = databaseref.child("posts").childByAutoId().key
let childupdates = ["/posts/\(self.loggedinuser!.uid)/\(key)/text ": newpost.text,"/posts/\(self.loggedinuser!.uid)/\(key)/time":"\(Date().timeIntervalSince1970)"
] as [String : Any]
self.databaseref.updateChildValues(childupdates)
dismiss(animated: true, completion: nil)
}
}
}