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 | |
import Moya | |
struct AsyncRequestError: Error { | |
// TODO: add Description | |
} | |
extension MoyaProvider { | |
// method #1 - using AsyncThrowingStream | |
func request(_ target: Target) async throws -> Response { |
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 | |
struct SampleView: View { | |
@State presentsSheet = false | |
var body: some View { | |
Button { presentsSheet.toggle() } label: { Text("Toggle Sheet") } | |
.uiKitSheet( | |
isPresented: $presentsSheet, | |
onDismiss: { print("dismissed!") }, |
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 | |
@propertyWrapper | |
struct Converted<T: Decodable, U: RawRepresentable>: Decodable where T == U.RawValue { | |
private let baseValue: T | |
var wrappedValue: U? { U(rawValue: baseValue) } | |
var projectedValue: T { baseValue } | |
init(from decoder: Decoder) 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
protocol AProtocol { | |
func callAsFunction() | |
} | |
class AClass: AProtocol { | |
func callAsFunction() { print("hi there") } | |
} | |
let a: any AProtocol = AClass() | |
a() // prints "hi there" |
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 | |
extension Publisher { | |
func makeHot() -> AnyPublisher<Output, Failure> { | |
let subject = PassthroughSubject<Void, Never>() | |
let publisher = map(Result.success) | |
.catch { Just(.failure($0)) } | |
.prefix(untilOutputFrom: subject) | |
.makeConnectable() | |
let connection = publisher.connect() |
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 UIKit | |
extension UICollectionViewCompositionalLayout { | |
static func waterfall( | |
columnCount: Int, | |
interItemSpacing: CGFloat = 0, | |
lineSpacing: CGFloat = 0, | |
itemCountProvider: @escaping (Int) -> Int, | |
itemSizeProvider: @escaping (IndexPath) -> CGSize, | |
sectionConfigurator: @escaping (inout NSCollectionLayoutSection) -> Void = { _ in }, |
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 | |
let uuid = NSUUID().uuidString //"3B156152-8CD1-4845-A85C-1722AACC2453" | |
uuid.replacingOccurrences(of: "-", with: "") //"3B1561528CD14845A85C1722AACC2453" |
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 | |
extension AsyncStream { | |
init( | |
_ elementType: Element.Type = Element.self, | |
bufferingPolicy limit: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded, | |
_ build: @escaping (AsyncStream<Element>.Continuation) async -> Void | |
) { | |
self = AsyncStream(elementType, bufferingPolicy: limit) { continuation in | |
Task { await build(continuation) } |
NewerOlder