This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Example of infinite recursion crash when asking for URL.bookmarkData in a unit test, | |
/// from a non-main queue. | |
/// | |
import XCTest | |
class BookmarkDataIssueTests: XCTestCase { | |
func testExample() throws { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by Marc Palmer on 13/02/2020. | |
// | |
// Usage: Add .debugMetrics(.yellow) or similar to any view | |
import Foundation | |
import SwiftUI | |
/// Renders the width and height of a view | |
struct DebugMetricsModifier: ViewModifier { | |
let colour: Color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import SwiftUI | |
struct SnapPointPreferenceData { | |
let frame: Anchor<CGRect> | |
} | |
struct SnapPointPreferenceKey: PreferenceKey { | |
typealias Value = SnapPointPreferenceData? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// ExtendedScrolView | |
// | |
// Created by Marc Palmer on 05/03/2020. | |
// Copyright © 2020 Montana Floss Co. Ltd. All rights reserved. | |
// | |
import SwiftUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noInputAction.perform(using: somePresenter) | |
noPresenterAction.perform(with: someInput) | |
noPresenterNoInputAction.perform() |