Skip to content

Instantly share code, notes, and snippets.

@5sw
5sw / ScrollViewWithPinning.swift
Created April 25, 2023 18:41
Pinning a view at the bottom of a scroll view
import SwiftUI
struct ContentView: View {
let itemHeight: CGFloat = 50
var body: some View {
GeometryReader { geo in
ScrollView {
VStack {
Text("Start")
@5sw
5sw / configurator.swift
Created July 21, 2021 09:18
Automatic builder for any Swift type
@dynamicMemberLookup
struct Configurator<T> {
var configure: (inout T) -> Void = { _ in }
subscript<V>(dynamicMember keyPath: WritableKeyPath<T, V>) -> Builder<V> {
.init(configure: configure, keyPath: keyPath)
}
static subscript<V>(dynamicMember keyPath: WritableKeyPath<T, V>) -> Builder<V> {
.init(configure: { _ in }, keyPath: keyPath)
@5sw
5sw / cycle.swift
Last active January 8, 2018 19:05
Shows how to break retain cycles
class A {
var b: B?
deinit {
print("A being deallocated")
}
}
class B {
var a: A?
deinit {
@5sw
5sw / hh_to_git.sh
Created January 4, 2015 17:45
Put daily Handmade Hero source code in git
#!/bin/bash
repo="HandmadeHero"
source="source"
if [ ! -d "$repo" ]
then
git init "$repo"
fi
@5sw
5sw / View.m
Last active February 16, 2018 03:35
UIView subclass that renders a SceneKit scene using SCNRenderer
#import <UIKit/UIKit.h>
#import <SceneKit/SceneKit.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
@interface View : UIView
@property (strong, nonatomic) SCNScene *scene;
- (void)renderFrame;
@5sw
5sw / QueueProxy.h
Created August 4, 2012 11:53
QueueProxy - call delegate methods on a different operation queue. Useful as a replacement for [NSURLConnection setDelegateQueue:]
#import <Foundation/Foundation.h>
@interface QueueProxy : NSProxy
+ (id) proxyForDelegate: (id)delegate onQueue: (NSOperationQueue *)queue;
@end