Ios 无法将类型为“\uu NSCFNumber”(0x1b4520df0)的值强制转换为“NSString”

Ios 无法将类型为“\uu NSCFNumber”(0x1b4520df0)的值强制转换为“NSString”,ios,swift,xcode,firebase,firebase-realtime-database,Ios,Swift,Xcode,Firebase,Firebase Realtime Database,我已尝试将as字符串值更改为int值,但仍然不起作用错误是不言自明的。您试图将数字转换为字符串。更换以下两行 let uid = FIRAuth.auth()?.currentUser?.uid let ref = FIRDatabase.database().reference().child("users").child((uid)!) ref.observeSingleEvent(of: .value, with: { snapshot

我已尝试将as字符串值更改为int值,但仍然不起作用

错误是不言自明的。您试图将数字转换为字符串。更换以下两行

 let uid = FIRAuth.auth()?.currentUser?.uid

            let ref = FIRDatabase.database().reference().child("users").child((uid)!)

            ref.observeSingleEvent(of: .value, with: { snapshot in

                if let dictionary = snapshot.value as? [String: AnyObject] {

                    let htest = dictionary["h"] as! String //error is mainly here signal SIGABRT

                    var inthtest = Int(htest)

                    if (inthtest==0){
                        self.checkPointsk()
                        print("scanning1")

避免此类崩溃的最佳方法是使用条件绑定

var inthtest = dictionary["h"] as! Int

@EICaptainv2.0不是真的//然后打印您的字典,并在更改为后发布!串到as!Int。。它第一次运行并将其更新到数据库,但第二次显示此错误。FireBaseSocialIn[1954:851767]无法将类型为“NSTaggedPointerString”0x1b45216b0的值强制转换为“NSNumber”0x1b4531c00。lldb@ElCaptainv2.0能否请您将Firebase结构的一个片段作为文本发布?请不要图片,以便我们可以查看快照中包含的内容?不是int,而是intnumber@Anbu.Karthik为什么在Swift中使用NSNumber?NSNumber可以按Int大小写,没有任何问题。最好在NSNumber上使用诸如Int、Double等Swift数据类型。@ebby94 FireBaseSocialFin[1951:850597]致命错误:在展开可选值时意外发现nil这是我得到的错误,当我按照您告诉我的那样做时。就像我说的,我已经试过用Int@ZahidAhmed看起来这个值不一致。它可以是string或Int,这是我所理解的。检查更新的answerlast部分和条件绑定,了解如何处理这两种情况。你当时做得不对。你强制施法的值为零。了解可选值的条件绑定。
var inthtest = dictionary["h"] as! Int
if var inthtest = dictionary["h"] as? Int{
    //Do your stuff
}
else if var inthtest = dictionary["h"] as? String{
    if let integerValue = Int(inthtest){
        //Do your stuff
    }
}