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 / 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 / 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 / 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 / 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 {
public protocol GridSection: SectionViewModel {
var lineItems: Int? { get }
var referenceItemWidth: CGFloat { get }
var sectionInsets: UIEdgeInsets { get }
var sectionHorizontalItemSpacing: CGFloat { 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 }
@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 / ColorCollectionViewCell.swift
Created November 26, 2018 12:20
An example UICollectionViewCell ready to be used in PowerTools Framework
class ColorCollectionViewCell: UICollectionViewCell {
struct Descriptor: ItemViewDescriptor, GridDescriptor {
let reuseIdentifier: String = String(describing: ColorCollectionViewCell.self)
let ratio: ViewRatio = ViewRatio(multiplier: 1.6, constant: 0.0)
}
}
@Oni-zerone
Oni-zerone / BaseSection.swift
Created November 26, 2018 12:26
An example section ready to be used in PowerTools Framework
struct BaseSection: SectionViewModel {
var header: ItemViewModel?
var items: [ItemViewModel]
var footer: ItemViewModel?
init(header: ItemViewModel? = nil, items: [ItemViewModel] = [], footer: ItemViewModel? = nil) {
self.header = header
open class Builder<Context> {
public init() { }
open func build(_ context: Context) -> UIViewController? {
return nil
}
}