gpt4 book ai didi

ios - 当值为 null 时,Swift 查询请求崩溃

转载 作者:行者123 更新时间:2023-11-30 11:53:25 27 4
gpt4 key购买 nike

检索到的查询结果

 "Adjusted_Lease_Value__c" = "0.0";
"Amount_Financed__c" = "23520.64";
"Assignment_Amount__c" = "19220.21";
"Category__c" = 4;
"Charge_Off_Amount__c" = "0.0";
"Committed_Funds__c" = "19220.21";
"Date_Assigned_Back_to_ACG__c" = "<null>"

我如何检索它们:

// Initial Access to Salesforce in order to query data
client.performLogin(accessUsername, password: accessPassword, fail:{ (fail) in

}) { (success) in

self.queryResult = self.client.query(getCasesSQL2)

for o: Any in self.queryResult.records() {

// This line fails
let test = (o as AnyObject).fieldValue("Date_Assigned_Back_to_ACG__c") as! String

// This works no problem
let AmountFinanced = ((o as AnyObject).fieldValue("Amount_Financed__c") as! String

}

当查询结果为“null”时,应用程序会崩溃。我该怎么办?

最佳答案

如果可能为零,则不要使用强制转换。

self.queryResult = self.client.query(getCasesSQL2)

for o: Any in self.queryResult.records() {

let test = (o as AnyObject).fieldValue("Date_Assigned_Back_to_ACG__c") as? String

let amountFinanced = ((o as AnyObject).fieldValue("Amount_Financed__c") as? String

}

关于ios - 当值为 null 时,Swift 查询请求崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48100694/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com