Skip to content

Instantly share code, notes, and snippets.

@jcmosc
jcmosc / printingStandardOutput.swift
Created April 30, 2025 18:39
Temporarily print standard output to a custom text output stream in Swift
import Foundation
/// Additionally writes any data written to standard output into the given output stream.
///
/// - Parameters:
/// - output: An output stream to receive the standard output text
/// - encoding: The encoding to use when converting standard output into text.
/// - body: A closure that is executed immediately.
/// - Returns: The return value, if any, of the `body` closure.
func printingStandardOutput<T>(to output: inout TextOutputStream, encoding: String.Encoding = .utf8, body: () -> T) async -> T {
@jcmosc
jcmosc / JCMMemoryEfficientMigrationManager.h
Created July 8, 2014 01:11
Memory Efficient Migration Manager
@import CoreData;
/**
A subclass of NSMigrationManager that is more memory efficient than
NSMigrationManager itself.
This class maintains its own source and destination instance association
tables, which store only the URI representation of the instances's object IDs,
rather than the objects themselves. This means that objects do not accumulate
@jcmosc
jcmosc / StoryboardController.h
Last active December 30, 2015 05:29
StoryboardController: A storyboard controller manages a set of view controllers described in a storyboard file that make up a portion of your app’s user interface. A storyboard controller is to a storyboard what a view controller is to a view. Whereas a view controller would manage a view heirachy that allows a user to perform a single task, a s…
//
// StoryboardController.h
// Ideas
//
// Created by James Moschou on 12/3/13.
// Copyright (c) 2013 James Moschou. All rights reserved.
//
#import <Foundation/Foundation.h>
@jcmosc
jcmosc / UIResponder+FirstResponder.h
Created May 25, 2013 06:23
A category on the UIResponder class to obtain the first responder object.
@interface UIResponder (FirstResponder)
+ (UIResponder *)firstResponder;
@end