I'm trying to get the size in Ko of an image which is placed in a remote server and check this to know if it is necessary to download it. I tried a lot of examples i found in this forum but nothing work for me with Xcode 8 and swift 4. First, i try to get the header like this:
func getHeader() {
for (index, item) in imgUrlArray.enumerated() {
let session = URLSession.shared
session.dataTask(with: item) {
(data, response, error)->Void in
if let responseData = data {
do {
let json = try
JSONSerialization.jsonObject(with: responseData,
options: JSONSerialization.ReadingOptions.allowFragments)
print(json)
} catch {
print("Could not serialize")
}
}
}.resume()
}
}
imgUrlArray
is an array with remote URLs like: http://www.test.com/image.jpg
In this case data is nil. Where is my mistake?