Instantly share code, notes, and snippets.

💭
Busy working on Concepts app and Flint framework

Marc Palmer marcpalmer

View GitHub Profile
View TyoeSafeBuilders.swift
//
// Paste this code into a playground to see the compiler error and have a shot at a solution.
// All suggestions gratefully received. This is really an exercise in seeing if there is a way to lock down
// intermediary command "binding" types to only those that relate to the same kind of Robot as the CommandBuilder expects.
//
// There is a compiler error when we try to add the actual binding to the builder:
//
// Collaborator with Constrained Self Conformance.playground:63:21: error: cannot convert
// value of type 'CommandBinding<MetalMickey, DanceCommand>' to expected argument type 'CommandBinding<_, _>'
// builder.add(dance)
View Flint-Subfeature-Iteration-Invoke-Example.swift
// Demo of iterating over subfeatures that all have a similar action and possibly performing that action.
/// Type-eraser for the action type so we can perform it irresepective of action type
struct AnyConditionalActionBinding<InputType, PresenterType> {
let _perform: (_ input: InputType, _ presenter: PresenterType) -> Bool
init<FeatureType, ActionType>(_ actionBinding: ConditionalActionBinding<FeatureType, ActionType>) where ActionType.InputType == InputType, ActionType.PresenterType == PresenterType {
_perform = { (_ input: InputType, _ presenter: PresenterType) -> Bool in
if let request = actionBinding.request() {
request.perform(input: input, presenter: presenter)
View .bash_profile
#
# Author: Marc Palmer
# Twitter: https://twitter.com/marcpalmerdev
# Blog: https://marcpalmer.net
#
# This is a .bash_profile file that you can write to your home directory to give
# you a custom shell prompt that will include the git branch and status of your
# current working dir as well as the current Xcode version.
#
# This is really handy when you're running multiple Xcode versions on your machine and have to run
View flint-conditional-conformance-6.swift
noInputAction.perform(using: somePresenter)
noPresenterAction.perform(with: someInput)
noPresenterNoInputAction.perform()
View flint-conditional-conformance-5.swift
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) {
View flint-conditional-conformance-4.swift
noInputAction.perform(using: somePresenter, with: .none)
noPresenterAction.perform(using: NoPresenter(), with: someInput)
noPresenterNoInputAction.perform(using: NoPresenter(), with: .none)
View flint-conditional-conformance-3.swift
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
}
}
View flint-conditional-conformance-2.swift
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) {
}
View flint-conditional-conformance-1.swift
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
}
}
View Protocols with PATs and composition.swift
//: Playground - noun: a place where people can play
import UIKit
protocol Action {
associatedtype Input
associatedtype Presenter
static func present(i: Input, p: Presenter)
}