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