Skip to content

Instantly share code, notes, and snippets.

@bestiosdeveloper
Created June 21, 2019 12:16
Show Gist options
  • Save bestiosdeveloper/7ebe8d079bfcfe86688dd0d33a090849 to your computer and use it in GitHub Desktop.
Save bestiosdeveloper/7ebe8d079bfcfe86688dd0d33a090849 to your computer and use it in GitHub Desktop.
import SwiftUI
import Combine
class MainHomeVM: BindableObject {
var articals: [Artical] = [] {
didSet {
didChange.send(self)
}
}
var didChange = PassthroughSubject<MainHomeVM, Never>()
func search(forQuery searchQuery: String) {
var param = JsonDictionary()
param["q"] = searchQuery
let todayStr = Date().add(days: -2)?.toString(dateFormat: "yyyy-MM-dd") ?? ""
if !todayStr.isEmpty {
param["from"] = todayStr
}
param["sortBy"] = "publishedAt"
param["apiKey"] = AppConstants.apiKey
APICaller.shared.callGetAllNewsAPI(param: param) { [weak self](success, errorMsg, artcl) in
if success {
self?.articals = artcl
}
else {
self?.articals = []
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment