Skip to content

Instantly share code, notes, and snippets.

@arifinfrds
Created August 1, 2018 03:22
Show Gist options
  • Save arifinfrds/4d4ae39572eaa410ef35015f6546844b to your computer and use it in GitHub Desktop.
Save arifinfrds/4d4ae39572eaa410ef35015f6546844b to your computer and use it in GitHub Desktop.
arifinfrds/iOS-MVVM-Alamofire/MVVM Alamofire/service/
import Foundation
import Alamofire
struct DataService {
// MARK: - Singleton
static let shared = DataService()
// MARK: - URL
private var photoUrl = "https://jsonplaceholder.typicode.com/photos"
// MARK: - Services
func requestFetchPhoto(with id: Int, completion: @escaping (Photo?, Error?) -> ()) {
let url = "\(photoUrl)/\(id)"
Alamofire.request(url).responsePhoto { response in
if let error = response.error {
completion(nil, error)
return
}
if let photo = response.result.value {
completion(photo, nil)
return
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment