小编caa*_*042的帖子

Swift Firebase 检查用户是否存在

我究竟做错了什么?我有一个像这张图片中显示的那样的数据库结构。 我的数据结构
在 appleDelegate.swift 中,我只想检查“用户”节点下是否确实存在某个用户令牌。也就是说,如果“用户”具有子 currentUserID(字符串标记)。我了解observeSingleEvent 是异步执行的。我在swift 中收到此错误:“应用程序窗口应在应用程序启动结束时有一个根视图控制器”。在“func application(_ application:UIApplication”)中,我有这个代码。我在下面还有我的完成处理程序函数。

if let user = Auth.auth().currentUser{
        let currentUserID = user.uid
        ifUserIsMember(userId:currentUserID){(exist)->() in
            if exist == true{
                print("user is member")
                self.window?.rootViewController = CustomTabBarController()
            } else {
                self.window?.rootViewController = UINavigationController(rootViewController: LoginController())
            }
        }

        return true
    } else {
        self.window?.rootViewController = UINavigationController(rootViewController: LoginController())
        return true
    }
}

func ifUserIsMember(userId:String,completionHandler:@escaping((_ exists : Bool)->Void)){
    print("ifUserIsMember")
    let ref = Database.database().reference()
    ref.child("users").observeSingleEvent(of: .value, with: { (snapshot) in
        if snapshot.hasChild(userId) {
            print("user exists")
            completionHandler(true)
        } else {
            print("user doesn't exist") …
Run Code Online (Sandbox Code Playgroud)

firebase completionhandler swift firebase-realtime-database

2
推荐指数
1
解决办法
2034
查看次数

Swift Double.remainder(dividingBy:) 返回负值

let num = 32.0
Double(num).remainder(dividingBy: 12.0)
Run Code Online (Sandbox Code Playgroud)

我得到 -4?...而不是 8.0...它从 8.0 中减去 12.0

我该如何解决?

negative-number modulus swift

1
推荐指数
1
解决办法
2430
查看次数