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
final class NetworkManager { | |
let baseURL: String | |
private var session = URLSession(configuration: URLSessionConfiguration.default, | |
delegate: nil, | |
delegateQueue: nil) | |
private let queue = DispatchQueue(label: "com.organization.network-manager", attributes: .concurrent) |
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
protocol RouteProtocol { | |
var stringValue: String { get } | |
var method: String { get } | |
} |
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
extension RickAndMortyService { | |
enum CharacterRoute: RouteProtcol { | |
case id(Int) | |
case base([Filters]) | |
var stringValue: String { | |
switch self { | |
case .id(let id): | |
return "character/\(id)" |
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
enum RickAndMortyService { | |
static let baseURL = "https://rickandmortyapi.com/api/" | |
static let manager = NetworkManager(baseURL: baseURL) | |
} |
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
enum RickAndMortyService { | |
static let baseURL = "https://rickandmortyapi.com/api/" | |
} |
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
struct Character: Codable { | |
let id: Int | |
let name: String | |
let status: String | |
let url: String | |
let species: String | |
let type: String | |
let gender: String | |
} |
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
static func searchBy(id: Int, completion: @escaping(Character?, Error?) -> ()) { | |
manager.sendRequest(route: Self.id(id), decodeTo: Character.self) { completion($0, $1)} | |
} | |
static func searchWith(filters: [Filters], completion: @escaping([Character]?, Error?) -> ()) { | |
struct SearchWithFiltersResponse: Decodable { | |
let info: Info | |
let results: [Character] | |
} |
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
struct Info: Decodable { | |
let count: Int | |
let pages: Int | |
let next: String? | |
let prev: String? | |
} |
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
RickAndMortyService.CharacterRoute.searchBy(id: 2) { character, error in | |
} | |
RickAndMortyService.CharacterRoute.searchWith(filters: [.name("morty")]) { characters, error in | |
} |
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 UIKit | |
final class TransitionDelegate: NSObject, | |
UIViewControllerTransitioningDelegate { | |
private let interactiveController = UIPercentDrivenInteractiveTransition() | |
private let duration = CATransaction.animationDuration() | |
func presentationController(forPresented presented: UIViewController, |
OlderNewer