In decoding JSON with Swift 4, I would like to convert a string during decoding into capital case. The JSON stores it as uppercase
For example
let title = "I CANT STAND THE RAIN"
print(title.capitalized)
How can I do this during the decoding process so the string is stored as capitalized in my model?
The only caveat is that I only want to capitalize one of the properties in the JSON (title) not the rest of them.
struct Book: Decodable {
let title: String
let author: String
let genre: String
init(newTitle: String, newAuthor: String, newGenre: String) {
title = newTitle
author = newAuthor
genre = newGenre
}
}
let book = try! decoder.decode(Book.self, from: jsonData)