Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Tartaglia danielt1263

  • Haneke Design
  • Tampa, FL
View GitHub Profile
@danielt1263
danielt1263 / TokenAcquisitionService.swift
Last active Jun 20, 2021
Token Acquisition Service for Combine
View TokenAcquisitionService.swift
//
// TokenAcquisitionService.swift
// CombineSandbox
//
// Created by Daniel Tartaglia on 11/27/19.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import Foundation
import Combine
@freak4pc
freak4pc / Combine+WithLatestFrom.swift
Last active May 10, 2021
withLatestFrom for Apple's Combine
View Combine+WithLatestFrom.swift
//
// Combine+WithLatestFrom.swift
//
// Created by Shai Mishali on 29/08/2019.
// Copyright © 2019 Shai Mishali. All rights reserved.
//
import Combine
// MARK: - Operator methods
View ZipMany.swift
import Combine
struct ZipMany<Element, Failure>: Publisher where Failure: Error {
typealias Output = [Element]
private let underlying: AnyPublisher<Output, Failure>
init<T: Publisher>(publishers: [T]) where T.Output == Element, T.Failure == Failure {
let zipped: AnyPublisher<[T.Output], T.Failure>? = publishers.reduce(nil) { result, publisher in
if let result = result {
View ObservableResultTransforms.swift
//
// ObservableResultTransforms.swift
//
// Created by Daniel Tartaglia on 5/10/2019.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import RxSwift
/**
@danielt1263
danielt1263 / RetryingTokenNetworkService.swift
Last active May 21, 2021
The TokenAcquisitionService automatically retry requests if it receives an unauthorized error. Complete with proof that it works correctly.
View RetryingTokenNetworkService.swift
//
// RetryingTokenNetworkService.swift
//
// Created by Daniel Tartaglia on 16 Jan 2019.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import Foundation
import RxSwift
View Combining Recipes.md

Recipes for Combining Observables in RxSwift

Several operators exist to combine multiple observables into one. This document shows the basics of the various combining operators and shows some more advanced recipes using them.

Combine Latest

The combineLatest operator is used whenever you have two or more observables emitting values, and you want access to the latest value emitted from each of them whenever one of them emits a new value. It can be used, for example, to combine a username and password to make a login request:

func example(username: Observable<String>, password: Observable<String>) {
    let credentials: Observable<(String, String)> = Observable.combineLatest(username, password)
View ObservableEventTransforms.swift
//
// ObservableEventTransforms.swift
//
// Created by Daniel Tartaglia on 9/22/18.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import RxSwift
/**
View EmitWhile.swift
//
// EmitWhile.swift
//
// Created by Daniel Tartaglia on 09/06/2018.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import Foundation
import RxSwift
View PaginationNetworkLogic.swift
//
// PaginationNetworkLogic.swift
//
// Created by Daniel Tartaglia on 4/9/17.
// Copyright © 2019 Daniel Tartaglia. MIT License
//
import RxSwift
struct PaginationUISource {
View Buffers.swift
// ObservableBuffer.swift
//
// Created by Daniel Tartaglia
// Copyright © 2019 Daniel Tartaglia. MIT License.
import RxSwift
extension ObservableType {
/**