I have the following situation:
Classes involved are
- ViewController (of type UIViewController)
- RequestHandler
- DataRequest (imports Alamofire for the request)
Step 1)
override func viewDidLoad() {
super.viewDidLoad()
requestHandler.getData(view: self)
}
So here, my instance of the RequestHandler class is calling its getData()-function.
Step 2)
func getData(view: ViewController) {
let dataRequest = DataRequest()
dataRequest.getDataTree(handler: self) { response in
view.saveData(dataTree: reponse)
}
}
In this getData method inside my class RequestHandler i'm creating an instance of the desired Request-class. In this case an instance of the class DataRequest. This instance then class its function getDataTree() and handles the response over to my ViewController by invoking the saveData()-function.
Step 3)
import Foundation
import SwiftyJSON
import Alamofire
class DataRequest {
func getDataTree(handler: RequestHandler, completion: @escaping ([String:[String:[String:[SomeStruct]]]]) -> ()) {
let requestURL = constants.Url.dataURL
Alamofire.request(requestURL, method: .post, encoding: URLEncoding.default)
.validate()
.responseJSON(completionHandler: { response in
completion(self.getServices(jsonData: JSON(data: response.data!)))
})
}
private func getServices(jsonData: JSON) -> [String:[String:[String:[SomeStruct]]]] {
var serviceDict: [String:[String:[String:[SomeStruct]]]] = [:]
for (k, subJson):(String, JSON) in jsonData {
let key = k
let dict: [String:[String:[SomeStruct]]] = getNames(jsonData: subJson)
serviceDict[key] = dict
}
return serviceDict
}
..followed by declaration of getNames-function etc until in the end, the SomeStruct objects in the array get parsed too.
So now that you got the background-information, my problem is the following: By debugging I found out that the function getDataTree is called and executed, but the getServices-function never executes, despite being called in the completion-block.
I've only started as a programmer less than a year ago, so my experience is limited. I might aswell just make a really trivial mistake.
Thanks alot for your help already!