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 / static.swift
Created December 18, 2018 15:24 — forked from gabrielepalma/static.swift
Static/dynamic dispatch
struct Dog : Animal {
var animalType: String {
return "dog"
}
}
protocol Animal {
var animalType: String { get }
@Oni-zerone
Oni-zerone / ItemViewModelBuilderContainer.swift
Last active December 11, 2018 09:54
ItemViewModel BuilderContainer extension
struct ColorItemViewModel: ItemViewModel {
var reuseIdentifier: String
var color: UIColor
}
extension ColorItemViewModel: BuilderContainer {
func getBuilder<Context>(_ contextType: Context.Type) -> Builder<Context>? {
@Oni-zerone
Oni-zerone / BuilderContainer.swift
Created December 11, 2018 09:40
BuilderContainer
public protocol BuilderContainer {
func getBuilder<Context>(_ contextType: Context.Type) -> Builder<Context>?
}
@Oni-zerone
Oni-zerone / InteractionFactory.swift
Last active December 11, 2018 09:59
The InteractionDelegate bridge to AbstractFactory
public typealias InteractionFactory = InteractionDelegate & AbstractFactory
public extension InteractionDelegate where Self: AbstractFactory {
func containerView(_ containerView: UIView, shouldSelect item: ItemViewModel) -> Bool {
return item is BuilderContainer
}
func containerView(_ containerView: UIView, didSelect item: ItemViewModel) {
@Oni-zerone
Oni-zerone / AbstractFactory.swift
Created December 11, 2018 09:25
AbstractFactory from PowerTools
public protocol AbstractFactory {
associatedtype Context
var context: Context { get }
var presenterViewController: UIViewController? { get }
func make(from builder: Builder<Context>) -> UIViewController?
@Oni-zerone
Oni-zerone / ExampleBuilder.swift
Created December 11, 2018 09:14
ExampleBuilder
open class ExampleBuilder<Context>: Builder<Context> {
var title: String
public init(title: String) {
self.title = title
super.init()
}
open override func build(_ context: Context) -> UIViewController? {
@Oni-zerone
Oni-zerone / InteractionDelegate.swift
Created December 11, 2018 08:52
The interactionDelegate protocol of PowerTools
public protocol InteractionDelegate: class {
func containerView(_ containerView: UIView, shouldSelect item: ItemViewModel) -> Bool
func containerView(_ containerView: UIView, didSelect item: ItemViewModel)
func containerView(_ containerView: UIView, shouldDeselect item: ItemViewModel) -> Bool
func containerView(_ containerView: UIView, didDeselect item: ItemViewModel)
open class Builder<Context> {
public init() { }
open func build(_ context: Context) -> UIViewController? {
return nil
}
}
@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
@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)
}
}