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 | |
// Diff objects for better test assertions. | |
// | |
// Implemented in a way that: | |
// 1. The compiler generates as much code as possible | |
// 2. You'll get a compiler error if you forget a property | |
// | |
// Nested support and collections left as an exercise for the reader. |
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 | |
// Diff values for better test assertions. | |
// | |
// Enums and collections left as an exercise for the reader. | |
// A difference between two values | |
struct Difference: CustomStringConvertible { | |
let path: String | |
let actual: String |
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
#if canImport(UIKit) | |
import UIKit | |
extension UIColor { | |
static var random: UIColor { | |
return UIColor( | |
red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...1) | |
) |
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 SwiftUI | |
extension Calendar { | |
func generateDates( | |
inside interval: DateInterval, | |
matching components: DateComponents | |
) -> [Date] { | |
var dates: [Date] = [] | |
dates.append(interval.start) |
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
@propertyWrapper | |
public struct Restorable<Value> { | |
public var wrappedValue: Value | |
public init(wrappedValue: Value, using undoManager: UndoManager = .init()) { | |
self.wrappedValue = wrappedValue | |
self.projectedValue = undoManager | |
} |
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
// | |
// (See usage below implementation) | |
// | |
// SwiftUI `CollectionView` type implemented with UIKit's UICollectionView under the hood. | |
// Requires `UIViewControllerRepresentable` over `UIViewRepresentable` as the type that allows | |
// for SwiftUI `View`s to be added as subviews of UIKit `UIView`s at all bridges this gap as | |
// the `UIHostingController`. | |
// | |
// Not battle-tested yet, but seems to be working well so far. | |
// Expect changes. |
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
public protocol HierarchyDescription { | |
associatedtype Child: HierarchyDescription | |
var children: [Child] { get } | |
var description: String { get } | |
} | |
extension HierarchyDescription { | |
public var hierarchyDescription: String { | |
var description = self.description | |
for child in children { |
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
// | |
// ExampleWindowReaderApp.swift | |
// Shared | |
// | |
// Created by Matthaus Woolard on 21/12/2020. | |
// | |
import SwiftUI | |
@main |
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
// Taken from Apple's App Dev Training: https://developer.apple.com/tutorials/app-dev-training/ | |
/// This color is either black or white, whichever is more accessible when viewed against the scrum color. | |
var accessibleFontColor: Color { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 | |
UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil) | |
return isLightColor(red: red, green: green, blue: blue) ? .black : .white | |
} |