Created
June 21, 2019 12:16
-
-
Save bestiosdeveloper/7ebe8d079bfcfe86688dd0d33a090849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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