Skip to content

Instantly share code, notes, and snippets.


Rui Peres RuiAAPeres

Block or report user

Report or block RuiAAPeres

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
RuiAAPeres / covariance_contravariance.swift
Last active Sep 16, 2019
Covariance and Contravariance in Swift
View covariance_contravariance.swift
import UIKit
// Based on
// > Denotes "a subtype of"
// UIButton > UIView > UIResponder > NSObject
// e.g. `UIButton` is a subtype of `UIView`
// This means that any function that takes a `UIView`, can receive a `UIButton`:
RuiAAPeres / SwiftUIBindsWithReactiveSwift.swift
Last active Dec 20, 2019
Couple of methods to bridge ReactiveSwift with SwiftUI
View SwiftUIBindsWithReactiveSwift.swift
import Combine
import ReactiveSwift
import SwiftUI
class AnySubscription: Subscription {
private let cancelable: Cancellable
init(cancelable: Cancellable) {
self.cancelable = cancelable
View SwiftUI Property Delegates.swift
/// `ObjectBinding` used as a way to create a `Binding` from a `BindableObject`. In this case the ViewModel
/// complies with `BindableObject` which is then translated into a `Binding` which is what `Toggle` is expecting
/// NOTE: Since it's a `DynamicViewProperty`, after its value is changed, the body will be updated.
class ViewModel: BindableObject {
let didChange = PassthroughSubject<ViewModel, Never>()
var isEnabled = false {
didSet {
View Flow_example.swift
public extension UIViewController {
var modalFlow: Flow {
return ModalFlow(self)
var navigationFlow: Flow {
guard let navigationController = self.navigationController else { return modalFlow }
return NavigationFlow(navigationController)
View phase3.swift
import Foundation
precedencegroup PipePrecedence {
associativity: left
higherThan: AssignmentPrecedence
infix operator |> : PipePrecedence
public func |> <T, U>(x: T, f: (T) -> U) -> U {
View phase2.swift
import Foundation
enum Result<T> {
case success(T)
case failure(String)
func map<U>(_ f: (T) -> U) -> Result<U> {
switch self {
case .success(let x): return .success(x |> f)
case .failure(let e): return .failure(e)
View phase1.swift
import Foundation
"4 5 + 3 +"
func calculator(_ input: String) -> Double {
return input |> split |> reversePolishNotation
func reversePolishNotation(_ input: [String]) -> Double {
var stack: [Double] = []
View foo.swift
struct MyModelDTO {
let property1: Type1
let property2: Type2
extension MyModelDTO {
init(model: MyModel_CoreData) {
self.init(property1: model.property1, property2: model.property2)
View bah.swift
class MyModel: NSObject {
var property1: Type1!
var property2: Type2!
View gist:07a8f3459532bbb952b1dd480ec0913c
Process: Xcode [3786]
Path: /Applications/
Version: 8.3 (12169)
Build Info: IDEFrameworks-12169000000000000~2
App Item ID: 497799835
App External ID: 821487965
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [3786]
You can’t perform that action at this time.