Skip to content

Instantly share code, notes, and snippets.

View esnssr's full-sized avatar

Eslam Nasser esnssr

View GitHub Profile
@esnssr
esnssr / Combine+Ext.swift
Created February 24, 2026 13:51
`AsyncStream` implementation from Combine Publisher
import Foundation
import Combine
extension AnyCancellable: @retroactive @unchecked Sendable {}
extension CurrentValueSubject: @retroactive @unchecked Sendable {}
public extension Publisher where Failure == Never, Output: Sendable {
var stream: AsyncStream<Output> {
AsyncStream { continuation in
let cancellable = self.sink { completion in
@esnssr
esnssr / AVPlayer+Ext.swift
Created February 24, 2026 13:05
`AsyncStream` periodicTimeValues for AVPlayer
import Foundation
import AVFoundation
public extension AVPlayer {
func periodicTimeValues(
forInterval interval: CMTime,
queue: dispatch_queue_t? = nil
) -> AsyncStream<TimeInterval> {
let (stream, continuation) = AsyncStream.makeStream(of: Double.self)
@esnssr
esnssr / FormatStyle.swift
Last active February 24, 2026 13:03
FormatStyle Example
public extension FormatStyle where Self == TimeFormatStyle<FloatingPointFormatStyle<Double>> {
static var time: TimeFormatStyle<FloatingPointFormatStyle<Double>> {
TimeFormatStyle(baseStyle: .number, countDirection: nil, formatter: .timeFormatter)
}
static func time(formatter: DateComponentsFormatter) -> TimeFormatStyle<FloatingPointFormatStyle<Double>> {
TimeFormatStyle(baseStyle: .number, countDirection: nil, formatter: formatter)
}