Skip to content

Instantly share code, notes, and snippets.

View huwr's full-sized avatar
🏡
Remote worker

Huw Rowlands huwr

🏡
Remote worker
View GitHub Profile
@huwr
huwr / Publisher+shareReplayOnce.swift
Created August 26, 2021 04:51
Combine Publisher share replace once
public extension Publisher {
/// A variation on [share()](https://developer.apple.com/documentation/combine/publisher/3204754-share)
/// that allows for buffering and replaying a single event to future subscribers.
///
/// - Parameter initialValue: The initial value of the buffer, if none has been emitted before.
/// - Returns: A publisher that replays the event to future subscribers.
func shareReplayOnce(initialValue: Output) -> Publishers.Autoconnect<Publishers.Multicast<Self, CurrentValueSubject<Output, Failure>>> {
multicast { CurrentValueSubject(initialValue) }
.autoconnect()
@huwr
huwr / NavFunApp.swift
Last active March 23, 2023 04:09
FB12076468
import SwiftUI
/*
In Xcode 14.3 RC1, running against iOS 16.4:
When you run this app, the first and second screens show fine. When you tap the last "Third Presentation" button, the last
screen should slide on.
For some reason, if you have the last few lines uncommented (the ones which mention SFSafariViewController, when you
tap the "Third Presentation" button, the app locks up and the CPU goes to 100%.