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
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 com.apple.dt.Xcode DVTEnableDockIconVersionNumber -bool YES
# Or set ShowDVTDebugMenu.
# Show Index in the Report navigator.
# https://pspdfkit.com/blog/2019/how-xcode-indexing-works-and-how-to-solve-problems/
defaults write com.apple.dt.Xcode IDEIndexShowLog -bool YES
@mayoff
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
mayoff / !README.md
Last active Feb 11, 2020
Debugging Objective-C blocks in lldb
View !README.md

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
@end

@implementation Foo
View FloatingViewController.swift
import UIKit
class FloatingButtonController: UIViewController {
private(set) var button: UIButton!
required init?(coder aDecoder: NSCoder) {
fatalError()
}
@mayoff
mayoff / SteppingSubscriber.swift
Created Dec 18, 2019
Custom Combine operator for stepping a publisher's signals through function
View SteppingSubscriber.swift
// See https://stackoverflow.com/q/59367202/77567
import Combine
import Foundation
extension Publisher {
func step(with stepper: @escaping (SteppingSubscriber<Output, Failure>.Event) -> ()) -> AnyCancellable {
let subscriber = SteppingSubscriber<Output, Failure>(stepper: stepper)
self.subscribe(subscriber)
return .init(subscriber)
@mayoff
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];
UIRectFill(CGRectInfinite);
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(gc, size.width / 2, size.height / 2);
@mayoff
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
mayoff / Main.storyboard
Created Sep 10, 2014
Storyboard with autolayout constraints for aspect-fit of a subview in a container view, for http://stackoverflow.com/a/25768875/77567
View Main.storyboard
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
You can’t perform that action at this time.