- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 observeSingleEvent 中,变量 num 更改为我想要的值,但就在它变回空值之后。我如何获得要更改的 num 值?
var num = Int()
FIRDatabase.database().reference().child("menus/Day1").observeSingleEvent(of: .value, with: {(snap) in
print(snap)
if let snapDict = snap.value as? [String:AnyObject]{
self.num = snapDict["date"] as! Int
print(num)
//returns the number I want
}
})
print(num)
//Returns an empty value
if num == 5 {
print("number is 5")
else {
print("number is not 5")
//goes to this
}
最佳答案
您需要对从 Firebase 返回的值进行的任何工作都必须在完成处理程序(方法调用的 with
部分)中完成。要使用/操作从 Firebase 获得的 num
值,您需要在完成处理程序中使用它。
var num = Int()
FIRDatabase.database().reference().child("menus/Day1").observeSingleEvent(of: .value, with: {(snap) in
print(snap)
if let snapDict = snap.value as? [String:AnyObject]{
self.num = snapDict["date"] as! Int
if self.num == 5 {
print("number is 5")
else {
print("number is not 5")
}
}
})
关于ios - 变量的值在 observeSingleEvent 中没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43071594/
我正在尝试获取一些用户的个人资料图片。这是我开始的代码: databaseRef.child("Users").queryOrderedByKey().observeSingleEvent(of: .
我一直在尝试弄清楚 firebase 如何在 swift 中工作。举个例子: let locationRef = FIRDatabase.database().reference(withPa
我的实时数据库是这样的: 如您所见,它只包含 1 个 child 。几分钟前,我在 RunningGames 中还有 4 个 child 。我在浏览器中删除了它们。现在调用这个时: private l
我想在应用启动时获取所需的应用版本号。但是我找不到正确的 key 。 我要获取此代码。我使用 observe single event 因为我使用这种方法来检查所需的应用程序版本号。此方法仅在应用程序
我在Firebase应用程序中收到“错误类型'FIRDatabaseReference'的值类型没有成员'observeSingleEvent'”的错误。我在firebase网站上找到了此代码,但是很
在 observeSingleEvent 中,变量 num 更改为我想要的值,但就在它变回空值之后。我如何获得要更改的 num 值? var num = Int() FIRDatabase
当我刷新 Collection View 时,我的数据重复 +1。当我拉动刷新此功能时,如何避免数组中出现重复条目?也用了 self.posts.removeAll() 还是没有结果。 var p
我在 Firebase 实时数据库中有问题和答案,我需要将其下载并放入数组中。我创建了一个函数,它接受一个参数并且应该返回两个数组 let data = fetchQuestions(category
在 iOS 应用程序中,我们在循环内多次调用 observeSingleEvent() 以填充列表: for i in 1...10 { ref.child("\(i)").observeSing
我的应用相当多地使用了 firebase 的 observeSingleEventOfType,我开始意识到我的应用的内存会随着时间的推移而增加。除了调用以下函数的测试按钮外,我已经注释掉了所有代码。
我想在另一个函数中使用variable_a。实际上,我想将这些数据加载到tableviewcell中。 func readFIRData() { var credentials:[Strin
当我第一次问这个问题时,我还没有真正做过研究。但是在 20 多个小时之后,我的结构与 Firebase 文档中的结构完全一样。但是,我无法访问闭包之外的任何数据。这是应该写入数据的结构: st
我试图在快速循环下调用“observeSingleEvent”,但它在本地循环完成后被调用 func fetchAllComments(){ let myGroup = DispatchGro
现在已经好几个小时了,我一直在浏览 Internet 论坛,试图找到解决我问题的方法,但我不知道发生了什么,所以我希望这里有人能提供帮助) 我有一个 swift 应用程序,在我的一个 View Con
我将 Firebase 数据库与 swift 结合使用。当我使用 databaseReference.observe(...) 进行观察时,我可以轻松地从 DatabaseReference 中删除观
背景: 我有一个应用程序,新用户可以在其中填写注册表单(包括用户名、电子邮件和密码)来注册帐户。当新用户提交表单时,应用程序会检查其 Firebase 数据库以查看用户名是否已被占用。这里的问题是 o
我正在尝试找回一个 child 的 child 。整个 snapshotValue 返回 null。当我检索与子项相同的数据(非嵌套)时,它检索得很好。 我正在使用 XCode 10 和 Swift
observeSingleEvent 在 Firebase 中呈现和提取数据时存在延迟。有没有办法来解决这个问题?我正在使用此函数来更新标签的文本。 func getthename() { v
我有一个 UITableView,它将使用此函数正确加载: channelRef?.observeSingleEvent(of: .value, with: { (snapshot) in
我正在尝试从 Firebase 检索登录用户的数据。但是,它不会进入 observeSigleEvent 方法并填充数据,因此,当涉及到 cellForRowAtIndexpath 方法时,posts
我是一名优秀的程序员,十分优秀!