Skip to content

Instantly share code, notes, and snippets.

View dafurman's full-sized avatar

David Furman dafurman

View GitHub Profile
@mbrandonw
mbrandonw / FB10144005.md
Last active March 22, 2024 17:05
iOS 16 Navigation API feedbacks

How to execute logic when NavigationLink is tapped?

FB10144005

Currently it doesn't seem possible to execute additional logic when a navigation link is tapped with the new NavigationLink(value:) initializer. When the link is tapped it updates path state all the way back at the root NavigationStack to drive navigation, but there are many times where we need to perform logic after the tap and before the drill down.

For example, after tapping a link we may want to pre-emptively load some data to show on the drill down screen. Or we may want to perform some form validation. Or we may want to track some analytics. This does not seem possible with the current link API.

A workaround is to use Buttons instead of NavigationLinks, but then you lose all of the styling and affordances given to links, such as chevrons when used in List.

If the API for NavigationLink cannot be changed to accomodate for this, perhaps a new ButtonStyle could be introduced that allows regular buttons to take on the sty

@ryanpato
ryanpato / XCUIElement+Wait.swift
Last active January 4, 2024 04:05
XCUIElement+Wait
//
// XCUIElement+Wait.swift
//
// Created by Ryan Paterson on 12/12/2020.
//
import XCTest
extension XCUIElement {
/// The period of time in seconds to wait explicitly for expectations.
@HiddenJester
HiddenJester / UnitTestingSceneDelegateGist.md
Last active March 20, 2024 14:38
Mocking SceneDelegate for Unit Tests on iOS 13

Replacing the SceneDelegate When Running Unit Tests

Overview

I've been working through the exercises in the excellent iOS Unit Testing by Example book by Jon Reid, which I highly recommend. However, the book is in beta at the moment and there are some curveballs thrown by iOS 13 that aren't handled in the text yet. Specifically, when I hit the section about using a testing AppDelegate class I thought "This is very good. But what about the SceneDelegate?"

In Chapter 4 the recommendation is to remove the @UIApplicationMain decoration and make a manual top-level call to UIApplicationMain. To wit:

import UIKit
@zntfdr
zntfdr / firebase-iOS-breakdown.swift
Last active March 27, 2024 15:06
Firebase iOS Version breakdown
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
@anandabits
anandabits / Safer SwiftUI Environment.md
Last active November 9, 2023 20:44
Towards a safer SwiftUI environment

Towards a safer SwiftUI environment

Swift UI's @EnvironmentObject is currently prone to runtime errors. If a view uses an environment object of a type that was not injected using environmentObject a fatalError occurs. This document sketches a design that would support compile-time checking of environment object usage. It requires a few language enhancements.

Tuple intersection types

Swift's protocol composition types such as Protocol1 & Protocol2 are a form of intersection types. Other forms of intersection types are possible. For example, Flow has object intersection types. Tuple intersection types for Swift would be very similar to these.

Below, you can see the examples in the Flow documentation converted to Swift's tuples:

@MuhsinFatih
MuhsinFatih / fix-macos-python.md
Last active May 18, 2024 01:09
How to recover from messed up python installation on mac, and never have to mess with apple's shitty python confusion factory

I am assuming you are here because like me, you installed a bazillion different python interpreters on mac and the whole thing is a spagetti. Today, I finally fixed my python installation. Whatever I install for python2 or python3 using pip JUST.WORKS.. My god! finally.

What the hell?

Here is what I had messed up, which you also probably did:

  • I had too many different python interpreters
  • Too many different symlinks which I lost track of
  • almost no package I installed with pip worked without a headache
  • any attempt to fix using online resources made it worse.
@anandabits
anandabits / HKT.swift
Last active December 25, 2023 00:57
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`
@cprovatas
cprovatas / BlockBasedSelector.h
Last active June 1, 2023 01:34
Block-Based Selectors in Swift
//
// BlockBasedSelector.h
//
// Created by Charlton Provatas on 11/2/17.
// Copyright © 2017 CharltonProvatas. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface BlockBasedSelector : NSObject
@macabeus
macabeus / listClasses.swift
Last active November 13, 2023 23:21
List all classes that subscribe a protocol
// Many thanks to Code Different: http://stackoverflow.com/a/42749141/3440266
import Foundation
struct ClassInfo : CustomStringConvertible, Equatable {
let classObject: AnyClass
let classNameFull: String
let className: String
init?(_ classObject: AnyClass?) {
guard classObject != nil else { return nil }
@miguelarauj1o
miguelarauj1o / podforceupdate.sh
Created April 7, 2016 19:37 — forked from mbinna/podforceupdate.sh
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update