I am using Salesforce ios sdk for my mobile application and there is a method to execute SOQL queries. For eg.,
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)")
}
}
Question I'll execute multiple SOQL queries with in the same class and there are different methods to handle the response. Now,
- Is there a way to get the reference of the request inside the
didLoadResponse? So, I can write switch statement to execute different functions. - If cannot reuse the delegate, do I need to create multiple delegate class to handle each and every response?
What is the better way to do it?
Update
request
SFRestRequest 0x1700cb130
endpoint: /services/data
method: GET
path: /v39.0/sobjects/Event/describe
queryParams: []
Other way to delegate is to create a separate class and define it.
SFRestAPI.sharedInstance().send(objectDescribe, delegate: testing());
class testing: NSObject, SFRestDelegate {
func request(_ request: SFRestRequest, didLoadResponse jsonResponse: Any) {
print(jsonResponse)
}
}
But the problem with the above, I have to create a class every time when I want to execute a SOQL query.
Thanks
I have an idea for you. Create a separate delegate class and in that class put an identifier. Then let that separate class delegate back to your view controller.
Make a new delegate class
Change the controller