Skip to content

Instantly share code, notes, and snippets.

View rpassis's full-sized avatar

Rogerio de Paula Assis rpassis

  • ANZx
  • Sunshine Beach, Australia
View GitHub Profile
@rpassis
rpassis / AnyPublisher+Extension.swift
Created September 1, 2021 22:23 — forked from IanKeen/AnyPublisher+Extension.swift
Extension to create an AnyPublisher to easily 'lift' async code into Combine
extension AnyPublisher where Failure: Error {
struct Subscriber {
fileprivate let send: (Output) -> Void
fileprivate let complete: (Subscribers.Completion<Failure>) -> Void
func send(_ value: Output) { self.send(value) }
func send(completion: Subscribers.Completion<Failure>) { self.complete(completion) }
}
init(_ closure: (Subscriber) -> AnyCancellable) {
import Combine
import ObjectiveC
import UIKit
private var eventSubjectKey = "viewcontroller_lifecycle_subject"
private var swizzlingPerformed = false
private final class LifecycleSubjectBag: NSObject {
let viewDidLoadSubject = PassthroughSubject<Void, Never>()
let viewWillAppearSubject = PassthroughSubject<Bool, Never>()
@rpassis
rpassis / xcbuild-debugging-tricks.md
Created March 22, 2021 14:23 — forked from ddunbar/xcbuild-debugging-tricks.md
Xcode new build system debugging tricks

New Build System Tricks

Command Line

alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
# THIS DOESNT WORK YET: xcbuild openIDEConsole  # … then switch to Xcode ➡️
xcbuild showSpecs
xcbuild build <foo.pif> [—target <target>]
@rpassis
rpassis / BetterXcodeJumpToCounterpartSwift.org
Created November 17, 2019 03:48 — forked from danielmartin/BetterXcodeJumpToCounterpartSwift.org
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@rpassis
rpassis / DeallocTests.swift
Last active July 14, 2019 20:32
Unit testing memory leaks
//
// DeallocTests.swift
//
// Created by Rogerio de Paula Assis on 7/14/19.
// Extracted from this CCH Melbourne talk: https://www.youtube.com/watch?v=514rJ1efv84
//
import XCTest
class DeallocTests: XCTestCase {
@rpassis
rpassis / Publisher+Unwrap.swift
Created July 3, 2019 14:57
Combine Recipe - Unwrapping an optional type operator
public protocol OptionalType {
associatedtype Wrapped
var value: Wrapped? { get }
}
extension Optional: OptionalType {
public var value: Wrapped? {
return self
}
}
@rpassis
rpassis / CoreDataChangeSetPlaygrounds.swift
Created January 13, 2019 18:07
Observe changes to a CoreData context using RxSwift
import UIKit
import CoreData
import Playgrounds
import RxSwift
import RxCocoa
@objc(ProductEntity)
final class ProductEntity: NSManagedObject {
@NSManaged public var uuid: String?
@NSManaged public var title: String?
@rpassis
rpassis / lldb_cheat_sheet.md
Created November 6, 2018 19:42 — forked from ryanchang/lldb_cheat_sheet.md
LLDB Cheat Sheet

LLDB Cheat Sheet

A complete gdb to lldb command map.

Print out

  • Print object
(lldb) po responseObject
(lldb) po [responseObject objectForKey@"state"]
  • p - Print primitive type
//
// EmitWhile.swift
//
// Created by Daniel Tartaglia on 09/06/2018.
// Copyright © 2018 Daniel Tartaglia. MIT License.
//
import RxSwift
/**
@rpassis
rpassis / HKT.swift
Created August 12, 2018 19:29 — forked from anandabits/HKT.swift
Emulating HKT in Swift
// This example shows how higher-kinded types can be emulated in Swift today.
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation.
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf
/// `ConstructorTag` represents a type constructor.
/// `Argument` represents an argument to the type constructor.
struct Apply<ConstructorTag, Argument> {
/// An existential containing a value of `Constructor<Argument>`
/// Where `Constructor` is the type constructor represented by `ConstructorTag`