I hereby claim:
- I am mitulmanish on github.
- I am min_max23 (https://keybase.io/min_max23) on keybase.
- I have a public key ASCPfkARcw8kzwxd2aWzpvrWLaqBgtYIfQJFax8ADdknkAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
enum ImageDownloadError: Error { | |
case url(errorDescription: String) | |
case data(errorDescription: String) | |
} | |
class CustomImageView: UIImageView { | |
var downloadTask: URLSessionDataTask? | |
func loadImageUsing(urlString string: String, | |
finishedLoadingImage: @escaping (Error?) -> ()) { |
struct AssetSaveHelper { | |
static var documentsDirectoryUrl: URL? { | |
return FileManager().urls(for: .cachesDirectory, in: .userDomainMask).first | |
} | |
static var cacheURL: URL? { | |
guard let url = documentsDirectoryUrl else { | |
return nil | |
} |
class DashboardCollectionViewController: UICollectionViewController { | |
override func viewDidLoad() { | |
collectionView?.register(DashboardCollectionViewCell.self, forCellWithReuseIdentifier: DashboardCollectionViewCell.cellIdentifier) | |
} | |
override func numberOfSections(in collectionView: UICollectionView) -> Int { | |
return 1 | |
} | |
enum ResourceError: Error { | |
case bundle | |
} | |
enum ResourceType: String { | |
case tv = "tv" | |
case movies = "movies" | |
var dataType: String { | |
switch self { |
extension UIView { | |
func pin(toView view: UIView) { | |
self.translatesAutoresizingMaskIntoConstraints = false | |
let topConstraint = self.topAnchor.constraint(equalTo: | |
view.topAnchor) | |
let bottomConstraint = self.bottomAnchor.constraint(equalTo: view.bottomAnchor) | |
let leadingConstraint = self.leadingAnchor.constraint(equalTo: view.leadingAnchor) | |
let trailingConstraint = self.trailingAnchor.constraint(equalTo: view.trailingAnchor) | |
NSLayoutConstraint.activate([topConstraint, | |
leadingConstraint, |
class DashboardCollectionViewCell: UICollectionViewCell { | |
static var cellIdentifier: String { | |
return "dashboard-cell-identifier" | |
} | |
var imageView: CustomImageView = { | |
let imageView = CustomImageView() | |
imageView.clipsToBounds = true | |
imageView.contentMode = .scaleToFill |
class MoviesViewModel: ViewModelProtocol { | |
var resourceType: ResourceType { | |
return .movies | |
} | |
var items: [Movie] = [Movie]() | |
typealias Item = Movie | |
required init?() { |
class TVShowsViewModel: ViewModelProtocol { | |
var items: [TVShow] = [TVShow]() | |
typealias Item = TVShow | |
var resourceType: ResourceType { | |
return .tv | |
} | |
required init?() { | |
guard let data = try? getData(forResourceType: resourceType) else { |
protocol ViewModelProtocol: class { | |
associatedtype Item: Equatable | |
init?() | |
var items: [Item] { get } | |
var count: Int { get } | |
func getData(forResourceType resource: ResourceType) throws -> Data | |
func extractItems(fromData data: Data) -> [Item] | |
var resourceType: ResourceType { get } | |
} |