Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
@fxm90
fxm90 / Redux.swift
Last active December 12, 2022 10:52
Playground showing how to use Redux with SwiftUI.
//
// Redux.playground
//
// Created by Felix Mau on 25.06.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import PlaygroundSupport
import SwiftUI
@fxm90
fxm90 / Combine-PassthroughSubject-CurrentValueSubject.swift
Last active November 17, 2021 00:51
Playground showing the difference between a `PassthroughSubject` and a `CurrentValueSubject`
//
// Combine-PassthroughSubject-CurrentValueSubject.playground
//
// Created by Felix Mau on 30.07.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import PlaygroundSupport
import Combine
extension Collection {
/// Returns an array of subsequences of maximum size `chunkSize`.
///
/// For example:
///
/// // ["ABCD", "EFGH", "IJ"]
/// "ABCDEFGHIJ".split(chunkSize: 4)
///
/// - parameter chunkSize: the maximum size of the returned subsequences.
/// - precondition: chunkSize > 0
@groue
groue / AsynchronousOperation.swift
Last active October 30, 2020 13:11
AsynchronousOperation
import Foundation
/// To create an operation:
///
/// 1. Subclass AsynchronousOperation, override main, and eventually cancel the
/// operation, or set result to a non-nil value.
///
/// 2. Use makeOperation { op in ... }, and eventually cancel the
/// operation, or set result to a non-nil value.
open class AsynchronousOperation<Output, Failure: Error>: Operation {
@atimca
atimca / unidirectional.swift
Created May 23, 2020 10:54
Tiny implementation of Unidirectional Architecture with Query based SideEffects.
import Combine
import Foundation
func loadNewsTitles() -> AnyPublisher<[String], Never> {
["title1", "title2"]
.publisher
.delay(for: .microseconds(500), scheduler: DispatchQueue.main)
.collect()
.eraseToAnyPublisher()
}
@RuiAAPeres
RuiAAPeres / reactiveswift+grdb.swift
Last active August 30, 2021 17:24
ReactiveSwift extensions for GRDB
/// This heavily based on the work done at RxGRDB
import GRDB
import ReactiveSwift
extension DatabasePool: ReactiveExtensionsProvider {}
extension DatabaseQueue: ReactiveExtensionsProvider {}
extension ValueObservation: ReactiveExtensionsProvider {}
extension DatabaseRegionObservation: ReactiveExtensionsProvider {}
@chriseidhof
chriseidhof / boilerplate.swift
Last active December 11, 2024 13:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@sunshinejr
sunshinejr / AttributedString.swift
Last active November 24, 2022 16:14
Different approach to Attributed Strings in Swift.
import Foundation
import class UIKit.UIImage
struct AttributedString: ExpressibleByStringInterpolation {
enum Attribute: Hashable {
enum ImportanceLevel: String, Equatable {
case very
case enough
}
case important(ImportanceLevel = .enough)
@atimca
atimca / Tiny_reactive.swift
Created April 2, 2020 15:50
A tiny realization of a reactive approach.
import PlaygroundSupport
import Foundation
class WeakRef<T> where T: AnyObject {
private(set) weak var value: T?
init(value: T?) {
self.value = value
}
@groue
groue / CancelBag.swift
Last active April 5, 2024 19:12
CancelBag
import Combine
import Foundation
/// A thread-safe store for cancellables which addresses usability pain points
/// with stock Combine apis.
///
/// ## Thread-safe storage of cancellables
///
/// let cancelBag = CancelBag()
/// cancellable.store(in: cancelBag)