类型为“任何吗?"的值没有成员“说明" [英] Value of type 'Any?' has no member 'description'

查看:74
本文介绍了类型为“任何吗?"的值没有成员“说明"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Firebase的初学者,我正沿着视频浏览,网址为 https ://www.youtube.com/watch?v = joVi3thZOqc& t = 301s ,我收到此错误类型为任何"的值?没有成员'description'这是我的代码:

Im a beginner to firebase and I am just following along the video at https://www.youtube.com/watch?v=joVi3thZOqc&t=301s and I'm getting this error " Value of type 'Any?' has no member 'description' " here is my code:

import UIKit
import Firebase
import FirebaseDatabase

class ViewController: UIViewController {
    @IBOutlet weak var conditionLable: UILabel!

    @IBAction func sunnyDidTouch(_ sender: Any) {
    }
    @IBAction func FoggyDidTouch(_ sender: Any) {
    }

    let rootRef = FIRDatabase.database().reference()



    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let conditionRef = rootRef.child("condition")
        conditionRef.observe(FIRDataEventType.value, with: { (snapshot : FIRDataSnapshot) in

            self.conditionLable.text = snapshot.value?.discription
        })
    }

}

推荐答案

主要目的是获得 condition 键的吗?

The main purpose is to get the value of condition key right?.

因此,请使用snap.value进行获取.

So use snap.value to get it.

let conditionRef = rootRef.child("condition")

conditionRef.observe(FIRDataEventType.value, with: { (snapshot : FIRDataSnapshot) in
  let weather = snap.value as? String

  self.conditionLable.text = weather
})

这篇关于类型为“任何吗?"的值没有成员“说明"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆