Skip to content

Instantly share code, notes, and snippets.

View mattadatta's full-sized avatar

Matthew Brown mattadatta

  • Ottawa, ON, Canada
View GitHub Profile
import Foundation
import CoreText
struct FontUtils {
enum Error: Swift.Error {
case dataProviderConstructionFailed
case cgFontConstructionFailed
case postScriptNameUnavailable
//
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
//
import SwiftUI
import UIKit
struct UIKitTextField : UIViewRepresentable {
@mattadatta
mattadatta / Anonymous.swift
Last active September 10, 2020 23:48
Rx's Observable.create -> Swift Combine "Anonymous"
import Foundation
import Combine
struct Anonymous<Output, Failure> : Publisher where Failure : Error {
var onSubscribe: (Observer) -> Cancellable
func receive<S>(subscriber: S) where Output == S.Input, Failure == S.Failure, S : Combine.Subscriber {
subscriber.receive(subscription: Sink(parent: self, downstream: subscriber))
}
@mattadatta
mattadatta / CollectionView.swift
Last active August 4, 2024 08:41
CollectionView.swift - UIKit's UICollectionView implemented in SwiftUI using UIViewControllerRepresentable
//
// (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.