Skip to content

Instantly share code, notes, and snippets.

View marcpalmer's full-sized avatar
💭
Busy working on Concepts app, and Captionista

Marc Palmer marcpalmer

💭
Busy working on Concepts app, and Captionista
View GitHub Profile
@marcpalmer
marcpalmer / flint-conditional-conformance-5.swift
Created April 27, 2018 16:19
Flint conditional conformance blog part 5
extension StaticActionBinding where ActionType.PresenterType == NoPresenter {
public func perform(with input: ActionType.InputType,
completion: ((ActionOutcome) -> ())? = nil) {
}
}
extension StaticActionBinding where ActionType.InputType == NoInput {
public func perform(using presenter: ActionType.PresenterType,
completion: ((ActionOutcome) -> ())? = nil) {
@marcpalmer
marcpalmer / flint-conditional-conformance-4.swift
Created April 27, 2018 16:18
Flint conditional conformance part 4
noInputAction.perform(using: somePresenter, with: .none)
noPresenterAction.perform(using: NoPresenter(), with: someInput)
noPresenterNoInputAction.perform(using: NoPresenter(), with: .none)
@marcpalmer
marcpalmer / flint-conditional-conformance-3.swift
Created April 27, 2018 16:18
Flint conditional conformance blog part 3
final class BeepAction: Action {
typealias InputType = NoInput
typealias PresenterType = NoPresenter
static func perform(with context: ActionContext<InputType>, using presenter: PresenterType, completion: ((ActionPerformOutcome) -> ())) {
// … not important for this example
}
}
@marcpalmer
marcpalmer / flint-conditional-conformance-2.swift
Created April 27, 2018 16:16
Flint conditional conformance blog part 2
public struct StaticActionBinding<FeatureType, ActionType>: CustomDebugStringConvertible
where FeatureType: FeatureDefinition, ActionType: Action {
public func perform(using presenter: ActionType.PresenterType,
with input: ActionType.InputType,
completion: ((ActionOutcome) -> ())? = nil) {
}
@marcpalmer
marcpalmer / flint-conditional-conformance-1.swift
Created April 27, 2018 16:16
Flint conditional conformance blog post part 1
final class ShowMessageAction: Action {
typealias InputType = String
typealias PresenterType = MessagePresenter
static func perform(with context: ActionContext<InputType>, using presenter: PresenterType, completion: ((ActionPerformOutcome) -> ())) {
// … not important for this example
}
}
@marcpalmer
marcpalmer / Protocols with PATs and composition.swift
Last active April 21, 2018 19:16
Shows a problem where it seems impossible to split a protocol with associated types to use composition and still be able to use discriminated on type
//: Playground - noun: a place where people can play
import UIKit
protocol Action {
associatedtype Input
associatedtype Presenter
static func present(i: Input, p: Presenter)
}
@marcpalmer
marcpalmer / AppUISpec.swift
Last active January 18, 2018 13:48
UISpec example #5
public class AppUISpec: UISpec {
/// Define the grid point size
public static let pointsPerGridUnit: CGFloat = 50.0
/// Convenient type aliases so that UISpecs inheriting from
/// this can use shorter forms.
public typealias Dimension = GridDimension<AppUISpec>
public typealias Radius = RadiusDimension<AppUISpec>
/// Standard unit multiples we use throughout
@marcpalmer
marcpalmer / UsageInAViewController.swift
Last active January 18, 2018 11:52
UISpect example #4
override func viewDidLoad() {
super.viewDidLoad()
// Normally views would take care of this themselves, not the view controller.
// This is a just a quick example.
OnboardingUISpec.Card.headingFont.apply(to: headingLabel)
OnboardingUISpec.Card.bodyFont.apply(to: welcomeTextLabel)
OnboardingUISpec.Card.backgroundColor.apply(to: [
onboardingCardView,
public class OnboardingUISpec: AppUISpec {
public enum Card {
public static let cornerRadius = 📏.smallRadius
public static let backgroundColor = 🖍.cardBackground
public static let padding = 📏.standardCardPadding
public static let headingFont = 🔤.massiveMarketingHeading
public static let bodyFont = 🔤.body
}
@marcpalmer
marcpalmer / uispec-example-2.swift
Created January 18, 2018 11:29
UISpec example #2
public typealias 🖍 = Colors
public typealias 📏 = Dimensions
public typealias 🔤 = Fonts