1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-16 07:10:31 +05:30
yattee/Model/SearchedVideosProvider.swift
Arkadiusz Fal 4bc70f351d Add search
2021-06-11 14:36:26 +02:00

20 lines
586 B
Swift

import Foundation
import SwiftyJSON
class SearchedVideosProvider: DataProvider {
@Published var videos = [Video]()
var query: String = ""
func load() {
let searchPath = "search?q=\(query.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!)"
DataProvider.request(searchPath).responseJSON { response in
switch response.result {
case let .success(value):
self.videos = JSON(value).arrayValue.map { Video($0) }
case let .failure(error):
print(error)
}
}
}
}