Skip to content

Instantly share code, notes, and snippets.

@arifinfrds
Created July 15, 2018 15:08
Show Gist options
  • Save arifinfrds/977d9cb044d48eef39a886473edfaa79 to your computer and use it in GitHub Desktop.
Save arifinfrds/977d9cb044d48eef39a886473edfaa79 to your computer and use it in GitHub Desktop.
arifinfrds/iOS-MVCS-Alamofire/MVCS Alamofire/store/DataService.swift
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