Ramcharan Reddy Ramcharan Reddy - 4 months ago 8
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() {
super.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"]!)'")
SFRestAPI.sharedInstance().sendRESTRequest(requestForGrandChilds,
failBlock:
{
error in print(error)
print("error block")
},
completeBlock:
{
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)"])")
//print(self.dataOfGrandChilds)
counter += 1
dispatch_async(dispatch_get_main_queue(),
{
print("Control came to main queue")
self.tableView.reloadData()
})
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

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

then write code for searching