【问题标题】:Calling GraphQL appSync requests and wait for the result to come back Swift iOS调用 GraphQL appSync 请求并等待结果返回 Swift iOS
【发布时间】:2021-03-23 02:51:36
【问题描述】:

我希望我的应用等到请求结果返回。所以在下面的块中,我想要做的是如果请求的查询返回空结果,我想调用“self.insertCreditRecord”。有人做过吗? appSyncClient?.fetch(query: selectQuery, cachePolicy: .fetchIgnoringCacheData) {(result, error) in 如果错误!= nil { 打印(错误?.localizedDescription ??“”) 返回 }

            result?.data?.listTranscriberConfigs?.items!.forEach {

                if let credit = Double($0?.value ?? "0.0")
                {
                    UserCredit.id = ""
                    UserCredit.id = $0?.id ?? ""
                    UserCredit.email = $0?.param ?? ""
                    UserCredit.credit =  credit
                }

                if UserCredit.id == "" {
                    self.insertCreditRecord(email: email)
                }
                print(($0?.param)! + " " + ($0?.value)!)
 
            }
        
        
        
    }

【问题讨论】:

    标签: ios swift aws-appsync


    【解决方案1】:

    你只需要在你的函数中使用完成处理程序来忽略空返回

    举例

    typealias CompletionHandler = (success:Bool) -> Void
    
    func downloadFileFromURL(url: NSURL,completionHandler: CompletionHandler) {
    
        // download code.
    
        let flag = true // true if download succeed,false otherwise
    
        completionHandler(success: flag)
    }
    
    // How to use it.
    
    downloadFileFromURL(NSURL(string: "url_str")!, { (success) -> Void in
    
        // When download completes,control flow goes here.
        if success {
            // download success
        } else {
            // download fail
        }
    })
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      • 2016-04-13
      • 2016-12-05
      • 2018-07-28
      • 2015-09-28
      相关资源
      最近更新 更多