英文:
Save integer without quotations into firebase database in swift
问题
我正在尝试使用setValue将一个数字放入Firebase数据库,但当我放入时,它总是变成一个字符串。示例:"10"而不是10。我已经仔细检查了我要设置的值实际上是一个整数或NSNumber。但都不起作用。
var modeResId = (self.modes[self.currModeNum].modeId as NSNumber)
ref.child(Mode.Parameter.MODE_ID).setValue(modeResId)
英文:
I am trying to put a number into firebase database with setValue, but it always changes to a string when I put it in. Example: "10" instead of 10. I have double checked that the value which I am setting is actually an int or NSNumber. None of which works.
var modeResId = (self.modes[self.currModeNum].modeId as NSNumber)
ref.child(Mode.Parameter.MODE_ID).setValue(modeResId)
答案1
得分: 1
将 modeId
先转换为 Int
,然后再将其 setValue
到 Firebase。
英文:
Hope this helps:
var modeResId = (self.modes[self.currModeNum].modeId as NSNumber)
ref.child(Mode.Parameter.MODE_ID).setValue(Int(modeResId) ?? 0) //If parsing fails then setValue 0
Convert modeId
into an Int
first and then setValue
into firebase.
答案2
得分: 0
问题在于我看错了键值。现在它正常工作。
英文:
The problem was that I was looking at the wrong key value. Now it works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论