Skip to content

Instantly share code, notes, and snippets.

View aduuub's full-sized avatar

Adam aduuub

View GitHub Profile
@aduuub
aduuub / ResultPublisherTests.swift
Created November 1, 2023 22:55
ResultPublishers Tests
import XCTest
// Depends on SP: https://github.com/albertbori/TestableCombinePublishers
import TestableCombinePublishers
final class ResultPublisherTests: XCTestCase {
func testSuccess() {
ResultPublisher<String, Error> { [weak self] in
self?.basicSuccess(completion: $0)
@aduuub
aduuub / ResultPublisher.swift
Created November 1, 2023 22:47
A Publisher that turns a completion with Result into a Combine Publisher
import Foundation
import Combine
public struct ResultPublisher<Success, Failure>: Publisher where Failure: Error {
public typealias Output = Success
public typealias Failure = Failure
public typealias ResultCallback = (Result<Success, Failure>) -> Void
@aduuub
aduuub / ViewModel.swift
Created August 13, 2023 08:26
Generic ViewModel
//
// TestViewModel.swift
// Test
//
// Created by Adam Wareing on 11/8/2023.
//
import UIKit
/// Model for storing a section and its contents
//
// KeyboardLayoutConstraint.swift
// TemplateProject
//
// Created by Adam Wareing on 12/08/19.
// Licenced under MIT.
//
// Based off: https://raw.githubusercontent.com/MengTo/Spring/master/Spring/KeyboardLayoutConstraint.swift
import UIKit
extension BaseNavigationController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard gestureRecognizer == interactivePopGestureRecognizer else {
return true // default value
}
// Disable pop gesture in three situations:
// 1) the view controller doesn't support being popped or doesn't want to be popped right now
extension BaseNavigationController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
(navigationController as? BaseNavigationController)?.duringPushAnimation = false
}
}
internal class BaseNavigationController: UINavigationController {
/// Indicates if a UIViewController is currently being pushed onto this navigation controller
private var duringPushAnimation = false
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self // to track when a view controller is being pushed
self.interactivePopGestureRecognizer?.delegate = self // for swipe the pop gesture recogniser
}
class BaseViewController: UIViewController {
var loadingView: UIView?
/// Called when the interactive view controller popping gesture is attempted from the right hand side.
/// The view controller should override this if it wants to change its behaviour.
///
/// - Returns: true if you want to prevent the interactive gesture.
func preventInteractivePopGesture() -> Bool {
let isNavBarVisible: Bool = navController?.isNavigationBarHidden == false
e -l Swift -- import MyNotesApp
e -l Swift -- let $syncView = unsafeBitCast(0x6000031550e0, to: SyncView.self)
// Read custom properties
e -l Swift -- print($syncView.syncState)
// Call your custom functions
e -l Swift -- $syncView.showSyncCompleted()
@aduuub
aduuub / LLDBTutorial-3.swift
Last active March 28, 2020 00:19
LLDBTutorial-3.swift
// We can also print it's constraints
e -l Swift -- print($label.constraints)
// [<NSContentSizeLayoutConstraint:0x6000031550e0 UILabel:0x7f913f90b7e0'All skills'.width == 95.5 Hug:251 CompressionResistance:750 (active)>, <NSContentSizeLayoutConstraint:0x600003155140 UILabel:0x7f913f90b7e0'All skills'.height == 33.5 Hug:251 CompressionResistance:750 (active)>]
// Or even modify its priorities
e -l Swift -- $label.constraints[0].constant = 100