【发布时间】:2017-08-18 21:53:14
【问题描述】:
我正在为我的移动应用程序使用 Salesforce ios sdk,并且有一种方法可以执行 SOQL 查询。例如,
class SfdcController: NSObject, SFRestDelegate {
let request = SFRestAPI.sharedInstance().request(forQuery:"SELECT Name FROM User LIMIT 10");
SFRestAPI.sharedInstance().send(request, delegate: self);
func request(_ request: SFRestRequest, didLoadResponse jsonResponse: Any)
{
print(jsonResponse)
}
func request(_ request: SFRestRequest, didFailLoadWithError error: Error)
{
self.log(.debug, msg: "didFailLoadWithError: \(error)")
}
}
问题 我将在同一个类中执行多个 SOQL 查询,并且有不同的方法来处理响应。现在,
- 有没有办法在
didLoadResponse中获取请求的引用?因此,我可以编写 switch 语句来执行不同的功能。 - 如果不能重用委托,是否需要创建多个委托类来处理每个响应?
有什么更好的方法?
更新
请求
SFRestRequest 0x1700cb130
endpoint: /services/data
method: GET
path: /v39.0/sobjects/Event/describe
queryParams: []
另一种委托方式是创建一个单独的类并定义它。
SFRestAPI.sharedInstance().send(objectDescribe, delegate: testing());
class testing: NSObject, SFRestDelegate {
func request(_ request: SFRestRequest, didLoadResponse jsonResponse: Any) {
print(jsonResponse)
}
}
但是上面的问题,我每次要执行 SOQL 查询时都必须创建一个类。
谢谢
【问题讨论】:
-
不确定他们的 api 但你能区分返回委托函数的请求对象吗?它可能有路径或查询,因此它可以分辨出哪个请求是什么??
-
@HMHero 我已经更新了这个问题。不,
request不包含任何引用。 -
那你能把请求缓存到数组或变量中,然后在回调中进行比较吗?我不喜欢这个主意。
-
Is there a way to get the reference of the request inside the didLoadResponse? So, I can write switch statement to execute different functions.jsonResponse中没有可以打开的某种引用吗?
标签: ios swift salesforce-ios-sdk