Skip to content

Instantly share code, notes, and snippets.

View Oni-zerone's full-sized avatar
🧗‍♀️
I may be hanging around.

Andrea Altea Oni-zerone

🧗‍♀️
I may be hanging around.
View GitHub Profile
@Oni-zerone
Oni-zerone / GridViewDescriptor.swift
Last active November 26, 2018 12:09
The GridViewDescriptor that contains the ViewRatio
public struct ViewRatio: Equatable {
public var multiplier: CGFloat
public var constant: CGFloat
}
public protocol GridDescriptor: GridItem {
var ratio: ViewRatio { get }
@Oni-zerone
Oni-zerone / ItemViewModel.swift
Created November 26, 2018 12:03
The updated itemViewModel with a referenced protocol as the ItemViewDescriptor
public protocol ItemViewDescriptor {
var reuseIdentifier: String { get }
}
public protocol ItemViewModel {
var descriptor: ItemViewDescriptor { get set }
var reuseIdentifier: String { get }
public protocol GridSection: SectionViewModel {
var lineItems: Int? { get }
var referenceItemWidth: CGFloat { get }
var sectionInsets: UIEdgeInsets { get }
var sectionHorizontalItemSpacing: CGFloat { get }
@Oni-zerone
Oni-zerone / InjectedRequestManager.swift
Last active October 25, 2018 07:28
An example of APIRequestManager injected in
//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 {
@Oni-zerone
Oni-zerone / ResourceCollectionViewCell.swift
Created October 22, 2018 15:31
A UICollectionViewCell with the ResourceCell conformance
class ResourceCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
}
extension ResourceCollectionViewCell: ResourceCell {
@Oni-zerone
Oni-zerone / AsyncResourceItemViewModel.swift
Created October 22, 2018 14:12
An Async loaded content ResourceItemViewModel
protocol ResourceCell {
func setupResource(title: String)
func setupResource(description: String)
func setupResource(imageURL URL: URL)
}
@Oni-zerone
Oni-zerone / ResourceItemViewModel.swift
Created October 22, 2018 13:55
A ResourceItemViewModel with the view represented by an interface. Resource is defined at bottom.
protocol ResourceCell {
func setupResource(title: String)
func setupResource(description: String)
func setupResource(imageURL URL: URL)
}
struct ResourceItemViewModel: ItemViewModel {
@Oni-zerone
Oni-zerone / StandardCellItemViewModel.swift
Created October 21, 2018 15:18
An itemViewModel of a simple cell
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 {
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
@Oni-zerone
Oni-zerone / CollectionViewModel.swift
Last active October 21, 2018 15:11
A UICollectionViewDataSource that will use a ViewModel representation of the items inside the collection
protocol ItemViewModel {
var reuseIdentifier: String { get }
func setup(_ cell: UICollectionReusableView, in collectionView: UICollectionView, at indexPath: IndexPath)
}
protocol SectionViewModel {
var headerItem: ItemViewModel? { get }