Ramcharan Reddy Ramcharan Reddy - 1 year ago 61
iOS Question

I could not gather the response properly .When I put break points it is working properly but without break points it is not giving proper outcome

override func viewDidLoad() {
let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Name,Id FROM Account where parentid='\(self.accountId)'");
SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: {error in print(error)}, completeBlock: { responce in print(responce)
self.dataRows = responce["records"] as! [NSDictionary]
var counter = 0;
for i in self.dataRows
let requestForGrandChilds = SFRestAPI.sharedInstance().requestForQuery("select Name,Id from Account where parentid='\(i["Id"]!)'")
error in print(error)
print("error block")
responceChild in
self.grandChilds = responceChild["records"] as! [NSDictionary]
self.dataOfGrandChilds["\(counter)"] = self.grandChilds
print("id of parent \(i["Id"]!) and counter \(counter) and data \(self.dataOfGrandChilds["\(counter)"])")
counter += 1
print("Control came to main queue")
print("getting to know\(self.dataOfGrandChilds)")

In the first request I'm trying fetch direct child accounts of an Id. In the completion block of 1st request I'm trying to fetch grand child accounts . dataRows is having data for section headers ( Which are direct child names). dataOfGrandChilds is dictionary that is holding section number as key and corresponding grandChilds array as its value.

When I put the break points at:

  1. line number 10.SFRestAPI.sharedInstance().sendRESTRequest(requestForGrandChilds,

  2. line number 23.counter += 1

the data in dataOfGrandChilds dictionary is properly setting and when remove the break points and execute the data in dataOfGrandschilds is setting inappropriately(i.e like for some other key,some other values is setting)

Please help me out.

Answer Source

get the complete data from ur database in viewDidLoad() and put that in [NSDictionary] type

then write code for searching

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download