Skip to content

Instantly share code, notes, and snippets.


Matt Curtis matt-curtis

View GitHub Profile
matt-curtis / DelegateForwarder.swift
Last active Mar 11, 2022
Delegate Forwarding in Swift. Useful for choosing some methods of a delegate to handle yourself and others to pass to a different delegate. Inspired by WebKit's Objective-C implementation of the same for UIScrollViewDelegate:…
View DelegateForwarder.swift
class DelegateForwarder<T: NSObjectProtocol>: NSObject {
// MARK: - Properties
weak var internalDelegate: T?
weak var externalDelegate: T?
var asConforming: T {
matt-curtis / SwiftUIKeyboardResizing.swift
Last active Aug 28, 2021
iOS 15 SwiftUI Keyboard Resizing (Bug?) Workaround
View SwiftUIKeyboardResizing.swift
import UIKit
import SwiftUI
class KeyboardViewController: UIInputViewController {
override func viewDidLoad() {
struct ContentView: View {
matt-curtis / AnimatableMemberHaving.swift
Last active Aug 22, 2021
AnimatableMemberHaving: A protocol that enables types whose members are made up of Animatable or VectorArithmetic-conforming properties to become Animatable themselves by specifying those members
View AnimatableMemberHaving.swift
import SwiftUI
/// A protocol that enables types whose members are made up of `Animatable` or `VectorArithmetic`-conforming properties
/// to become `Animatable` themselves by specifying those members.
/// Here's an example of how to use this protocol:
/// ```
/// struct CornerRadii: AnimatableMemberHaving {
matt-curtis / NumberPadDoneBtn.h
Last active Dec 31, 2020
Done Button for UIKeyboard NumberPad (must be set as inputAccessoryView)
View NumberPadDoneBtn.h
#import <UIKit/UIKit.h>
@interface NumberPadDoneBtn : UIView
@interface NumberPadButton : UIButton
matt-curtis /
Last active Dec 22, 2020
CALayer.shadowPath and CALayer.path don't overshoot when spring animated.

Playground demonstrating CALayer.shadowPath's failure to overshoot when spring animated.

matt-curtis / linkgrabber.js
Last active Sep 13, 2020
JS Link Grabber - Uses TextArea to Acquire Links Dropped onto Pages
View linkgrabber.js
var LinkGrabber = {
textarea: null,
/* Textarea Management */
attach_ta: function(){
if(LinkGrabber.textarea != null) return;
var textarea = LinkGrabber.textarea = document.createElement("textarea");
textarea.setAttribute("style", "position: fixed; width: 100%; margin: 0; top: 0; bottom: 0; right: 0; left: 0; z-index: 99999999");
matt-curtis / LocalServer.swift
Created Mar 18, 2020
Really simple example showing how to create a basic local HTTP server in Swift
View LocalServer.swift
import Foundation
import Cocoa
private enum Constants {
static let crlf: Character = "\r\n"
matt-curtis / MOJavaScriptObject.m
Last active Aug 22, 2019
MOJavaScriptObject function execution
View MOJavaScriptObject.m
@import JavaScriptCore;
/// Retaining MOJavaScriptObject retains your JSContext/JSObject as well
@interface MOJavaScriptObject : NSObject
@property (readonly) JSObjectRef JSObject;
@property (readonly) JSContextRef JSContext;
matt-curtis / gist:c0fa7aa820d6257e7b2a
Last active Aug 21, 2019
UINavigationBar Multiline Title
View gist:c0fa7aa820d6257e7b2a
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationItem.titleView = ({
UILabel *titleView = [UILabel new];
titleView.numberOfLines = 0;
titleView.textAlignment = NSTextAlignmentCenter;
titleView.attributedText = [[NSAttributedString alloc] initWithString:@"2\nLINES" attributes:
View SubstringFontReporting.js
let sketch = require('sketch')
let settingsAttribute = getSettingsAttributeForKey_Value(kLowerCaseType, kLowerCaseSmallCapsSelector)
function applySubstringFontModification() {
let document = sketch.getSelectedDocument()
let textLayer = document.selectedLayers.layers[0]