このサイトをお手本にしてユーザーのローケーション(緯度)を数値としてRealtimeDatabaseに読み込ませたいのですが下記のコードないでエラーが発生しうまくいきません。教えて下さい。
PS 緯度の取得は成功していますのでそのコードは省きました。
swift
1import MapKit 2import CoreLocation 3import Firebase 4 5class ViewController: UIViewController { 6 7 @IBOutlet weak var mapView: MKMapView! 8 let locationManager = CLLocationManager() 9 var ref: DatabaseReference! 10 @IBOutlet weak var longitude: UILabel! 11 @IBOutlet weak var latitude: UILabel! 12 13 override func viewDidLoad() { 14 super.viewDidLoad() 15 16 locationManager.delegate = self 17 18 ref = Database.database().reference() 19 20 } 21 @IBAction func selectBar(_ sender: UISegmentedControl) 22 { 23 self.ref.child("test").child(user.uid).setValue(["latitude": latitude.text]) 24 //Use of unresolved identifier 'user'がエラーとして表示されています。 25 } 26 27}
selectBar で user.uid として user を参照していますが, user が定義されていないので, そのエラーが出ています. なので, user を定義しましょう. おそらく, Auth.auth().currentUser だと思います.
ご返信ありがとうございます。
Authというのはどんな意味になりますか?
let user = Auth.auth().currentUserと入力したらUse of unresolved identifier 'Auth'とまた出ています。どうしたら良いでしょう?
おそらく Pod に Firebase/Auth が入っていないかもしれません. こちらを参考にしてください.
https://firebase.google.com/docs/auth/ios/start
podにauthを入れました
しかしuidの下にエラーとしてValue of optional type 'String?' must be unwrapped to a value of type 'String'が出ています。
must be unwrapped to a value of type 'String' とググりましょう.
回答1件
あなたの回答
tips
プレビュー