Skip to content

Instantly share code, notes, and snippets.

Rob Mayoff mayoff

Block or report user

Report or block mayoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mayoff / ContentView.swift
Created Feb 26, 2020
SwiftUI gradients spanning multiple views
View ContentView.swift
import SwiftUI
struct BubbleFramesValue {
var framesForKey: [AnyHashable: [CGRect]] = [:]
var gradientFrame: CGRect? = nil
struct BubbleFramesKey { }
extension BubbleFramesKey: PreferenceKey {
View gist:bcb5fc06b79f8b0a0270ebf48e38d4a1
# Show the Xcode version number over the Dock icon.
defaults write DVTEnableDockIconVersionNumber -bool YES
# Or set ShowDVTDebugMenu.
# Show Index in the Report navigator.
defaults write IDEIndexShowLog -bool YES
mayoff / ConversationView.swift
Created Feb 14, 2020
playground demonstrating SwiftUI PreferenceKey, EnvironmentKey, and GeometryReader
View ConversationView.swift
import SwiftUI
import PlaygroundSupport
struct EqualWidthKey: PreferenceKey {
static var defaultValue: CGFloat? { nil }
static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
switch (value, nextValue()) {
case (_, nil): break
case (nil, let next): value = next
mayoff / !
Last active Feb 11, 2020
Debugging Objective-C blocks in lldb
View !

The attached lldb command pblock command lets you peek inside an Objective-C block. It tries to tell you where to find the source code for the block, and the values captured by the block when it was created.

Consider this example program:

#import <Foundation/Foundation.h>

@interface Foo: NSObject

@implementation Foo
View FloatingViewController.swift
import UIKit
class FloatingButtonController: UIViewController {
private(set) var button: UIButton!
required init?(coder aDecoder: NSCoder) {
mayoff / SteppingSubscriber.swift
Created Dec 18, 2019
Custom Combine operator for stepping a publisher's signals through function
View SteppingSubscriber.swift
// See
import Combine
import Foundation
extension Publisher {
func step(with stepper: @escaping (SteppingSubscriber<Output, Failure>.Event) -> ()) -> AnyCancellable {
let subscriber = SteppingSubscriber<Output, Failure>(stepper: stepper)
return .init(subscriber)
mayoff / makeAnimatedGif.m
Created Feb 16, 2013
Example of creating an animated GIF on iOS, with no 3rd-party code required. This should also be easy to port to OS X.
View makeAnimatedGif.m
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
static UIImage *frameImage(CGSize size, CGFloat radians) {
UIGraphicsBeginImageContextWithOptions(size, YES, 1); {
[[UIColor whiteColor] setFill];
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(gc, size.width / 2, size.height / 2);
mayoff / Arrow.swift
Last active Oct 29, 2019
UIBezierPath category to create an arrow (now with a Swift version!)
View Arrow.swift
// Swift 2.2 syntax / API
import UIKit
extension UIBezierPath {
class func arrow(from start: CGPoint, to end: CGPoint, tailWidth: CGFloat, headWidth: CGFloat, headLength: CGFloat) -> Self {
let length = hypot(end.x - start.x, end.y - start.y)
let tailLength = length - headLength
mayoff / Main.storyboard
Created Sep 10, 2014
Storyboard with autolayout constraints for aspect-fit of a subview in a container view, for
View Main.storyboard
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="" version="3.0" toolsVersion="6245" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<plugIn identifier="" version="6238"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
You can’t perform that action at this time.