Skip to content

Instantly share code, notes, and snippets.

View PaulWoodIII's full-sized avatar

Paul Wood III PaulWoodIII

View GitHub Profile
@ryanashcraft
ryanashcraft / Using-NavigationDestinationLink.swift
Last active July 11, 2019 04:49
Here's a working implementation of controlled push/pop NavigationView actions in SwiftUI with NavigationDestinationLink.
@vmanot
vmanot / PresentationLink2.swift
Created July 7, 2019 09:55
PresentationLink bug workaround for SwiftUI (Xcode b3)
extension UIApplication {
/// The top most view controller
static var topMostViewController: UIViewController? {
return UIApplication.shared.keyWindow?.rootViewController?.visibleViewController
}
}
extension UIViewController {
/// The visible view controller from a given view controller
var visibleViewController: UIViewController? {
import Foundation
#if os(Linux)
import Glibc
#endif
struct Random {
#if os(Linux)
static var initialized = false
#endif
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing
var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5]
func partition(v: Int[], left: Int, right: Int) -> Int {
var i = left
for j in (left + 1)..(right + 1) {
if v[j] < v[left] {
i += 1
(v[i], v[j]) = (v[j], v[i])
}
}
@jmont
jmont / maybe.m
Last active March 30, 2016 16:27
Swift Monads
// Swift Monads -- Maybe
// Juan C. Montemayor (@norsemelon)
// This operator can be used to chain Optional types like so:
// optionalVal >>= f1 >>= f2
// where f1 and f2 have type `Any -> Any?`
//
// If a value is ever nil, the chain short-circuits and will result in nil.
// This is a much neater way to do this than using the if syntax specified in
// the Swift iBook.
@TimMedcalf
TimMedcalf / tableViewKeyboardHandling.m
Last active May 6, 2024 14:21
The easy & reliable way of handling UITableView insets when the keyboard is shown. This works unchanged no matter where the table view is on the screen (including dealing with orientation, hierarchy, container view controllers & all devices)
/*
One of the first things someone new to iOS Development finds is that dealing with the keyboard is trickier
than they think it should be. Simply changing the scrolling extents of a UITableView (or UIScrollView, or
UICollectionView) that is partially covered by they keyboard reveals a lot about the internals of how iOS
works and highlights various "gotchas" that need to be considered.
There are various ways to know that a keyboard has been shown - but observing some specific notifications
provides a reliable way to allow you to modify your views to deal with it.
@lxcid
lxcid / gist:2586763
Last active October 4, 2015 05:38
Call resume() to stop the block from exercising the run loop and break out of the loop/block. Failure to call resume() will cause the test to hang indefinitely. This is useful to testing asynchronous actions like AFNetworking operations. See https://gist.github.com/2215212 With some reference from https://github.com/icanzilb/MTTestSemaphore, I w…
typedef void (^LXSResumeBlock)(void);
typedef void (^LXSRunLoopBlock)(LXSResumeBlock resume);
// Call resume() to stop the block from exercising the run loop and break out of the loop/block.
// Failure to call resume() will cause the test to hang indefinitely.
// This is useful to testing asynchronous actions like AFNetworking operations. See https://gist.github.com/2215212
// With some reference from https://github.com/icanzilb/MTTestSemaphore, I was able to simplify this method.
inline void LXS_exercisesRunLoopInBlock(LXSRunLoopBlock block) {
__block BOOL keepRunning = YES;
block(^{ keepRunning = NO; });
while (keepRunning && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.03]]) {
@markd2
markd2 / BNRDiggyDict.h
Created March 20, 2012 13:45
Objective-C Literals, part 2 support files.
#import <Foundation/Foundation.h>
@interface BNRDiggyDict : NSObject
// React to object indexing. Would be nice to have a @protocol for this
- (id) objectForKeyedSubscript: (id) key;
- (void) setObject: (id) thing forKeyedSubscript: (id<NSCopying>) key;
// And for fun, it also can react to scalar indexing.
// Returns the N'th key of the top-level collection.
@saetia
saetia / gist:1623487
Last active May 1, 2024 19:55
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat