Qustion
I have a following structure
class UITableViewController (Presentation) -> class Contents(Domain) -> class API(Infrastructure)
Contents class gets raw data via API class and forms contents and then passes to UITableViewController.
I would like to use Alamofire to do Networking in API class.
I’ve looked through stackoverflow and I only found examples that UITableViewController directly accesses API class. Direct access from Presentation layer to Infrastructure layer is something we should not do. Like this How to return value from Alamofire
How do I achieve implementing Alamofire into DDD structure?
I want to achieve something like this
UITableViewController
class MyTableViewController: UITableViewController {
var contents: Contents?
override func viewDidLoad() {
super.viewDidLoad()
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0)) {
// do some task
self.contents = Contents.get("MyContents")
self.tableView.reloadData()
}
}
}
Contents
class Contents: NSObject {
static func get(contentsName: String) -> Contents {
let data = MyAPI.getRequest("https://xxxx.com/myContents")
// Form contents
let contents = ContentsFactory(data)
return contents
}
}
API
class MyAPI: NSObject {
static getRequest(url) -> NSData {
// Get and return data using alamofire
}
}