Skip to content

Instantly share code, notes, and snippets.

💭
Busy working on Concepts app and Flint framework

Marc Palmer marcpalmer

💭
Busy working on Concepts app and Flint framework
Block or report user

Report or block marcpalmer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@marcpalmer
marcpalmer / TypealiasDefaultingInSubProtocol_TypeAliasNaturalApproach.swift
Created May 17, 2019
Example of sub-protocol typealias defaulting which results in compiler warning to use protocol constraints
View TypealiasDefaultingInSubProtocol_TypeAliasNaturalApproach.swift
import Foundation
// ****************************************************************************************
//
// Example of trying to supply a default type for an associated type in a sub-protocol
// and helper functions that use this default type in an extention on that sub-protocol.
// The natural way to achieve this by defining the typealias in the sub-protocol produces
// a compiler warning and fix-it suggesting use of protocol constraint.
//
// This approach: typealias
@marcpalmer
marcpalmer / TypealiasDefaultingInSubProtocol_AssociatedTypeRestatingApproach.swift
Last active May 17, 2019
Example of trying to avoid sub-protocol typealias defaulting compiler warning using associatedtype to re-state the type
View TypealiasDefaultingInSubProtocol_AssociatedTypeRestatingApproach.swift
import Foundation
// ****************************************************************************************
//
// Example of trying to supply a default type for an associated type in a sub-protocol
// and helper functions that use this default type in an extention on that sub-protocol.
// The natural way to achieve this by defining the typealias in the sub-protocol produces
// a compiler warning and fix-it suggesting use of protocol constraint.
//
// This approach: Re-stating the associated type as a more specific type
@marcpalmer
marcpalmer / TyoeSafeBuilders.swift
Last active Jan 2, 2019
Trying to find a way to make typesafe builders constrained on a Self type
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)
@marcpalmer
marcpalmer / Flint-Subfeature-Iteration-Invoke-Example.swift
Last active Aug 13, 2018
An example of how you might iterate over a bunch of discrete features that provide similar functionality, such as photo filters
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)
@marcpalmer
marcpalmer / .bash_profile
Last active May 30, 2018
Change your macOS bash prompt to include Xcode version and git branch + status
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
@marcpalmer
marcpalmer / flint-conditional-conformance-6.swift
Created Apr 27, 2018
Flint conditional conformance blog part 6
View flint-conditional-conformance-6.swift
noInputAction.perform(using: somePresenter)
noPresenterAction.perform(with: someInput)
noPresenterNoInputAction.perform()
@marcpalmer
marcpalmer / flint-conditional-conformance-5.swift
Created Apr 27, 2018
Flint conditional conformance blog part 5
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) {
@marcpalmer
marcpalmer / flint-conditional-conformance-4.swift
Created Apr 27, 2018
Flint conditional conformance part 4
View flint-conditional-conformance-4.swift
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 Apr 27, 2018
Flint conditional conformance blog part 3
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
}
}
@marcpalmer
marcpalmer / flint-conditional-conformance-2.swift
Created Apr 27, 2018
Flint conditional conformance blog part 2
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) {
}
You can’t perform that action at this time.