G
G
Gleb2021-09-11 18:37:31
Swift
Gleb, 2021-09-11 18:37:31

How to pass data to viewModel?

There are two variables

private var result = [Company]()
 private var viewModels = [NewsTableViewCellViewModel]()


Structure
struct APIResponce: Codable {
    let company: Company
}

struct Company: Codable {
    let name: String
    let employees: [Employee]
}


An error occurred in the function
private func fetchPeople(completed: ((Bool) -> Void)? = nil) {
        APICaller.shared.getTopStories { [weak self] json in
            switch json {
            case .success(let result):
                self?.result.append(contentsOf: result)
                
// не могу положить данные 
  //              self?.viewModels.append(contentsOf: result ({ viewModels in
  //                  return NewsTableViewCellViewModel()
 //               }))
                
            }
        }
    }


I tried to do this, but it didn’t work out.
613ccc5cdf338599392990.png

I understand that these are problems from a poor understanding of the syntax, but you can indicate what caused the error, I don’t understand how to pass data to the viewModel

.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2021-09-11
@shevzoom

Read the text of the error - it says that it is not possible to assign an object of type TYPE to type [TYPE].
Those. - banal type mismatch. You are trying to assign one object to a variable that contains an array of objects.
upd. An error was found - skills is an array, and the author assigned a line to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question