G
G
Gleb2021-07-31 22:54:04
Swift
Gleb, 2021-07-31 22:54:04

How to add image upload via uuid?

I'm trying to re-load Image instead of URL by UUID.
now the Image is in a https://leonardo.osnova.io/<uuid>

structure that accepts a uuid:

struct Image: Codable {
    /// тот самый uuid котоырй хочу добавить
    let uuid: UUID!
    
    enum CodingKeys: String, CodingKey {
        case uuid
    }
}


Here I am trying to pass this data to the viewModel.
private func fetchTopStories() {
        APICaller.shared.getTopStories { [weak self] json in
            switch json {
            case .success(let result):
                self?.result = result
                self?.viewModels = result.compactMap({
                    NewsTableViewCellViewModel(
                        name: $0.data?.subsite?.name ?? "unknown",
                        author: $0.data?.author?.name ?? "No name",
                        title: $0.data?.title ?? "NO TITLE",
                        subtitle: $0.data?.blocks?.first?.data.text ?? "",
                        // здесь приложение крашится
                        imageURL: URL( string: "https://leonardo.osnova.io/ + \($0.data?.blocks?[1].data.items?.first?.image.data.uuid)" ?? "noImahe load")
//                        imageURL: URL(string: $0.cover?.url ?? " :( ")
                    )
                })
                
                DispatchQueue.main.async {
                    self?.tableView.reloadData()
                }
            case .failure(let error):
                print(error)
            }
        }
    }


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        let article = result[indexPath.row]
        var id = article.data?.blocks?[1].data.items?.first?.image.data.uuid!
//        var myurl = URL(string: "https://leonardo.osnova.io/" + \(id!.uuidString))

        guard let url = URL(string: "https://leonardo.osnova.io/ + \(id!.uuidString)")  else {
            return
        }   
    }


after that, the application gives an error and no longer starts, where is the mb cant?
6105c0d677c64817359690.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2021-08-01
@shevzoom

I suspect that, most likely, the problem is in $0.data?.blocks?[1]tk. here it is explicitly stated "to take the second element of the array".
By the way!!! What does debug give?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question