Skip to content

Instantly share code, notes, and snippets.

@arifinfrds
Created August 1, 2018 03:28
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save arifinfrds/ddfe432cac91e19065224f45de34d2ab to your computer and use it in GitHub Desktop.
arifinfrds/iOS-MVVM-Alamofire/MVVM Alamofire/view/controller/ViewController.swift
import UIKit
import SDWebImage
class ViewController: UIViewController {
// MARK: - Outlet
@IBOutlet weak var headerImageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
// MARK: - Injection
let viewModel = PhotoViewModel(dataService: DataService())
// MARK: - View life cycle
override func viewDidLoad() {
super.viewDidLoad()
attemptFetchPhoto(withId: 8)
}
// MARK: - Networking
private func attemptFetchPhoto(withId id: Int) {
viewModel.fetchPhoto(withId: id)
viewModel.updateLoadingStatus = {
let _ = self.viewModel.isLoading ? self.activityIndicatorStart() : self.activityIndicatorStop()
}
viewModel.showAlertClosure = {
if let error = self.viewModel.error {
print(error.localizedDescription)
}
}
viewModel.didFinishFetch = {
self.titleLabel.text = self.viewModel.titleString
self.subtitleLabel.text = self.viewModel.albumIdString
self.headerImageView.sd_setImage(with: self.viewModel.photoUrl, completed: nil)
}
}
// MARK: - UI Setup
private func activityIndicatorStart() {
// Code for show activity indicator view
// ...
print("start")
}
private func activityIndicatorStop() {
// Code for stop activity indicator view
// ...
print("stop")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment