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
public struct ViewRatio: Equatable { | |
public var multiplier: CGFloat | |
public var constant: CGFloat | |
} | |
public protocol GridDescriptor: GridItem { | |
var ratio: ViewRatio { 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
public protocol ItemViewDescriptor { | |
var reuseIdentifier: String { get } | |
} | |
public protocol ItemViewModel { | |
var descriptor: ItemViewDescriptor { get set } | |
var reuseIdentifier: 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
public protocol GridSection: SectionViewModel { | |
var lineItems: Int? { get } | |
var referenceItemWidth: CGFloat { get } | |
var sectionInsets: UIEdgeInsets { get } | |
var sectionHorizontalItemSpacing: CGFloat { 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
//The standard Interface to make requests and get AsyncContent | |
protocol RequestManager { | |
func getContent(_ resourceId: Int, completion: @escaping (Resource.AsyncContent?, Error?) -> ()) | |
} | |
//The concrete Implementation of the interface, this object is responsible to do the real Network request and parse the result. | |
struct APIRequestManager: RequestManager { | |
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
class ResourceCollectionViewCell: UICollectionViewCell { | |
@IBOutlet weak var titleLabel: UILabel! | |
@IBOutlet weak var descriptionLabel: UILabel! | |
@IBOutlet weak var imageView: UIImageView! | |
} | |
extension ResourceCollectionViewCell: ResourceCell { |
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 ResourceCell { | |
func setupResource(title: String) | |
func setupResource(description: String) | |
func setupResource(imageURL URL: URL) | |
} |
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 ResourceCell { | |
func setupResource(title: String) | |
func setupResource(description: String) | |
func setupResource(imageURL URL: URL) | |
} | |
struct ResourceItemViewModel: ItemViewModel { |
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 StandardCellViewModel: ItemViewModel { | |
let title: String | |
var reuseIdentifier: String { | |
return "cell" | |
} | |
func setup(_ cell: UICollectionReusableView, in collectionView: UICollectionView, at indexPath: IndexPath) { | |
guard let cell = cell as? StandardCell else { |
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
class MVVMCollectionViewDataSource: NSObject, UICollectionViewDataSource { | |
var model: [SectionViewModel] = [] | |
func numberOfSections(in collectionView: UICollectionView) -> Int { | |
return self.model.count | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return self.model[section].items.count |
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 ItemViewModel { | |
var reuseIdentifier: String { get } | |
func setup(_ cell: UICollectionReusableView, in collectionView: UICollectionView, at indexPath: IndexPath) | |
} | |
protocol SectionViewModel { | |
var headerItem: ItemViewModel? { get } |