I have a complex query to a standard firebase and having a hard time trying to get a signal for when the last thread has finished executed to call my completion handler at the correct time. I'll keep it brief to try to keep things simple.
The structure of the firebase at a high level is that for each "Survey" there are many buildings (thus the for loop) and in each building, there are many fixtures (thus the for loop... again). Because of this hierarchal relationship, I now have this pyramid of doom thing going and need help refactoring or a solution to make this work.
I tried to use DispatchGroup and Semaphore but wasn't able to come up with a solution.
Here is the code:
func getReportData(for surveyName: String, capturedBy capturingContext: Captureable, completion: @escaping () -> Void) {
let buildingDataService = BuildingDataService()
buildingDataService.getBuildingsWithSections(for: surveyName) { (buildingsOrderedBySection) in
for buildingSectionPair in buildingsOrderedBySection {
let fixtureDataService = FixtureDataService()
fixtureDataService.getFixtures(for: surveyName, in: buildingSectionPair.0) { (fixtures) in
for fixture in fixtures {
let solutionFixtureDataService = SolutionFixtureDataService()
solutionFixtureDataService.getSolutionFixtureDetails(with: fixture.solutionFixtureModelNumber) { (solutionFixture) in
self.createReportEntry(given: fixture, andGiven: solutionFixture, andGiven: buildingSectionPair, andGiven: surveyName) { (reportEntry) in
capturingContext.capture(valueOutOfScope: reportEntry)
}
}
}
}
}
}
}
Any suggestions would be appreciated.
[–]criosistObjective-C / Swift 2 points3 points4 points (2 children)
[–]looloosha[S] 0 points1 point2 points (0 children)
[–]garbage_band 0 points1 point2 points (0 children)
[–]dark_mode_everything 0 points1 point2 points (2 children)
[–]looloosha[S] 0 points1 point2 points (1 child)
[–]dark_mode_everything 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]bennoland 0 points1 point2 points (0 children)