I am trying to see what is the latest and greatest way to retrieve json data in swift 4 (using Codable structure).
I have the following json data in a remote url:
[
{
"products": [
{
"productid": "01",
"price": "01"
},
{
"productid": "02",
"price": "02"
}
]
}
]
I have also setup the corresponding codable structure. My questions is what would be the correct way to retrieve this data using the latest techniques for swift 4.
I am seeing various ways such as:
- DataManager.getJSONFromURL ...
- let jsonData = try Data(contentsOf: URL ...
- let task = URLSession.shared.dataTask(with: url) ...
- try JSONSerialization.data...
I would like to know which is the correct (latest) format for retrieving json data using swift 4 from a remote URL. Thank you.