Answer the question
In order to leave comments, you need to log in
How to update dynamically string in mvc model?
I get links every minute in a different number
How to correctly update them in Services in order to display media files in
view 1. View
var viewModel = HomeViewModel()
func configureViewModel() {
viewModel.resultClosure = { [weak self] listModel in
guard let image = listModel.uiImage else { return }
self?.updateImageViewConstraint(nil, image: image)
}
}
class HomeViewModel {
var service = Services()
var listModel = [ListModel]() {
didSet {
DispatchQueue.main.async { [weak self] in
guard let self = self else {
return
}
self.resultClosure?(self.listModel[0])
}
}
}
let placeholderImage = UIImage(named: "placeholder")
var updatedImge : UIImage?
var resultClosure: ((ListModel) -> Void)?
var stringUrl: StringUrl!
func fetchData() {
service.makeRequest() { (result: Result<[ListModel]>) in
switch result {
case .success(let listModel):
self.listModel = listModel
return
case .failure(let error):
print("\n HomeViewModel fetchData failure \(error) \n")
return
}
}
}
}
class Services {
let urlSession: URLSession
let imageProvider = ImageProvider()
let dynamicLinkfromStruct = "Dynamic Link From Struct!!!"
init(urlSession: URLSession = .shared) {
self.urlSession = urlSession
}
func makeRequest(completionHandler: @escaping (Result<[ListModel]>) -> Void) {
guard let url = URL(string: dynamicLinkfromStruct) else { return }
imageProvider.loadImages(from: url) { (image) in
do {
let result = [ListModel.init(imageUrl: self.url, uiImage: image)]
completionHandler(.success(result))
} catch {
completionHandler(.failure(error ))
}
}
}
}
struct ListModel {
let imageUrl: String?
let uiImage: UIImage?
}
struct GetManager {
static func showContent(pasteboard: String) {
switch onlyLinkAbsoluteString.validURL {
case true:
// Ссылки приходят тут
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question