I have the following struct
struct APIResource<T> {
let urlRequest: NSMutableURLRequest
let resource: T
let parse: (NSData) -> T
}
I also have the following view controller. It's job it is to ask the network stack to load the resource from the network. Once it is done, it will call the build function to build the appropriate view controller and adds it as a child view controller
final class LoadingVCL: UIViewController {
init<T>(_ resources: APIResource<T>, build: ((T) -> UIViewController)) {
super.init(nibName: nil, bundle: nil)
//ask the network stack for the data
//once data is loaded, I call the build closure
//to return a view controller and add it as a childviewcontroller
}
I am struggling to extend this LoadingVC to accept an array of resources and load them before adding the view controller.
I came across this when following this tutorial.
Edit One
For Instance, suppose I have the following resources
let resourceOne = APIResource<Int>(urlRequest: NSMutableURLRequest(), resource: 1, parse: { _ in return 1})
let resourceTwo = APIResource<Double>(urlRequest: NSMutableURLRequest(), resource: 1, parse: { _ in return 1})
let resourceThree = APIResource<String>(urlRequest: NSMutableURLRequest(), resource: "1", parse: { _ in return "1"})
I am trying to figure out a way for the view controller to accept an array of resources with different types.
Any help would be appreciated. Thanks
initis also a bad idea