Dota hero characters and their stats. In this project i have use Moya for api work with ReactiveRx, Kingfisher for loading Images, SkeletonView for shimmer and Reusable for simple working.
MyPods:
- pod 'Alamofire'
- pod 'Moya/RxSwift'
- pod 'RxSwift'
- pod 'RxCocoa'
- pod 'Kingfisher'
- pod 'SkeletonView'
- pod 'Reusable'
- pod 'NVActivityIndicatorView', '~> 4.8.0'
TIP (How to manage data and best way to call api using Moya)
import Foundation
import Moya
class NetworkManager {
static let shared: NetworkManager = NetworkManager()
let provider = MoyaProvider<Service>()
func callAPI(forEntity service: Service, completion: @escaping (Bool, String, HERO?) -> Void) {
provider.request(service) { result in
switch result {
case let .success(response):
let decoder = JSONDecoder()
let arrData = try! decoder.decode(HERO.self, from: response.data)
completion(true, "Success", arrData)
case .failure:
completion(false, "Failure", nil)
}
}
}
}
import Foundation
class ViewModel {
var mainData: HERO?
func getData(completion: @escaping (Bool, String) -> Void) {
NetworkManager.shared.callAPI(forEntity: .heroStats) { [weak self] isSuccess, message, resultData in
guard let self = self else { return }
if isSuccess {
self.mainData = resultData
print(message)
} else {
print(message)
}
completion(isSuccess, message)
}
}
}