textViewに書いた文章をcreateメソッドで保存しようとしたところ下記のエラーが出ました。
ネットで調べてもそれらしい記事が出なかったのでどなたか解決法を教えてくださると幸いです
swift
1import UIKit 2import Firebase 3class WritePopupViewController: UIViewController { 4 @IBOutlet weak var mainText: UITextView! 5 6 @IBAction func cancel(_ sender: Any) { 7 dismiss(animated: true, completion: nil) 8 } 9 10 @IBAction func send(_ sender: Any) { 11 create() 12 } 13 let ref = FIRDatabase.database().reference() 14 override func viewDidLoad() { 15 super.viewDidLoad() 16 17 // Do any additional setup after loading the view. 18 } 19 20 override func didReceiveMemoryWarning() { 21 super.didReceiveMemoryWarning() 22 // Dispose of any resources that can be recreated. 23 } 24 25 func create() { 26 //textFieldになにも書かれてない場合は、その後の処理をしない 27 guard let text = mainText.text else { return } 28 29 //ロートからログインしているユーザーのIDをchildにしてデータを作成 30 //childByAutoId()でユーザーIDの下に、IDを自動生成してその中にデータを入れる 31 //setValueでデータを送信する。第一引数に送信したいデータを辞書型で入れる 32 //今回は記入内容と一緒にユーザーIDと時間を入れる 33 //FIRServerValue.timestamp()で現在時間を取る 34 self.ref.child((FIRAuth.auth()?.currentUser?.uid)!).childByAutoId().setValue(["user": (FIRAuth.auth()?.currentUser?.uid)!,"content": text, "date": FIRServerValue.timestamp()]) 35 dismiss(animated: true, completion: nil) 36 } 37 38 39}
あなたの回答
tips
プレビュー