This looks more like a UIKit question. Someone may come by and help, but you'd have better luck asking over Apple Developer Forums since UIKit is an Apple's private framework.
On a side note:
Did you step through the code (with the debugger)? It might help you realize what's going on. Especially if the code doesn't execute something you'd expect.
Try to check the values too, the publishedAt string looks like this: "2020-08-22T18:55:36Z"
If you separate the logic out:
import Foundation
let string = "2020-08-22T18:55:36Z"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
if let time = dateFormatter.date(from: string) {
}
You'd realize that the dateFormat doesn't match the string (try it in playground). You'd actually use "yyyy-MM-dd'T'HH:mm:ss'Z'" to read from the string, the use another formatter to convert it back to string (or just change the dateFormat).
let string = "2020-08-22T18:55:36Z"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
if let date = dateFormatter.date(from: string) {
dateFormatter.dateFormat = "yyyy-MM-dd"
let newString = dateFormatter.string(from: date)
print(newString)
}
PS
I'd suggest that you use JSONDecoder instead of JSONSerialization.