In the data of my wordpress json I have the following:
[
{
id: 10033,
title: {
rendered: "My title"
},
content: {
rendered: "Sample text html",
}
_embedded: {
wp:featuredmedia: [
{
source_url: "https://domain.com/myimage.jpg",
}
]
}
}
I have my structures in the OffersData.swift file
struct JsonSosTalleres : Codable {
let id : Int
let title : Title?
let content : Content?
let embedded : Embedded?
enum CodingKeys: String, CodingKey {
case id = "id"
case title = "title"
case content = "content"
case embedded = "_embedded"
}
}
struct Title : Codable {
let rendered : String?
enum CodingKeys: String, CodingKey {
case rendered = "rendered"
}
}
struct Content : Codable {
let rendered : String?
enum CodingKeys: String, CodingKey {
case rendered = "rendered"
}
}
struct Embedded : Codable {
let featuredmedia : [Featuredmedia]?
enum CodingKeys: String, CodingKey {
case featuredmedia = "wp:featuredmedia"
}
}
struct Featuredmedia : Codable {
let urlimage : String
enum CodingKeys: String, CodingKey {
case urlimage = "source_url"
}
}
All this data I want to pass to a UITableView using JSON Decodable, I get the title correctly in the table but I have problems to call the url of the image:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tablaOfertas.dequeueReusableCell(withIdentifier: "ofertacell") as? OfertasTableViewCell else { return UITableViewCell() }
cell.tituloPost.text = datosOfertas[indexPath.row].title?.rendered // funciona ok
cell.imagePost.text = datosOfertas[indexPath.row].embedded?.featuredmedia?.urlimage // error : Value of type '[Featuredmedia]' has no member 'urlimage'
return cell
}
Any suggestions why it does not work or how would you call the URL of the image?
The title if it catches me correctly, but with the code this code for a iamgen:
cell.imagePost.text = datosOfertas[indexPath.row].embedded?.featuredmedia?.urlimage
me dice: Value of type '[Featuredmedia]' has no member 'urlimage'