Skip to content

Instantly share code, notes, and snippets.

Richard Turton jrturton

Block or report user

Report or block jrturton

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
jrturton / testimage.swift
Created Nov 19, 2018
Make a date-stamped test image
View testimage.swift
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 400, height: 400))
let image = renderer.image {
context in
let text = "TEST IMAGE \n\(Date())" as NSString
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
View UIView+Snapshots.swift
import UIKit
// Snapshot utilities
extension UIView {
func snapshotView(view: UIView, afterUpdates: Bool) -> UIView {
let snapshot = view.snapshotViewAfterScreenUpdates(afterUpdates)
snapshot.frame = convertRect(view.bounds, fromView: view)
return snapshot
View Coalescing in swift
import Foundation
func coalesce<T>(args: T?...) -> T? {
for possible in args {
if let actual = possible {
return actual
return nil
jrturton / gist:89ce72a87e1b0661eccb
Created Oct 2, 2014
Removing a core data store
View gist:89ce72a87e1b0661eccb
// Need to remove anything matching the first part - there are also logging files alongside the SQLite file itself.
// Typical directory contents are:
// Name.sqlite, Name.sqlite-shm, Name.sqlite-wal
NSURL *folderURL = [url URLByDeletingLastPathComponent];
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:folderURL includingPropertiesForKeys:nil options:0 error:nil];
jrturton / UIImageOrientation to TIFF orientation
Created Feb 27, 2014
Converting UImageOrientation to TIFF orientation values
View UIImageOrientation to TIFF orientation
switch (originalOrientation)
case UIImageOrientationUp:
orientationValue = @1;
case UIImageOrientationDown:
orientationValue = @3;
case UIImageOrientationLeft:
orientationValue = @8;
jrturton / gist:6881601
Created Oct 8, 2013
Increment build number at every archive or release build
View gist:6881601
if [ $CONFIGURATION = "Release" ] || [ $CONFIGURATION = "Dev" ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
jrturton / gist:6364558
Last active Dec 21, 2015
Navigation back buttons themed like iOS7, for iOS 5 and 6
View gist:6364558
// Appearance proxy methods
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage backButtonImage] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(7.0, 0.0) forBarMetrics:UIBarMetricsDefault];
// The image above is generated by this method
+(UIImage *)backButtonImage
View UIImage+HLImages.m
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
[color setFill];
CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0];
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
jrturton / NSString+URLCharacters.m
Created Jul 31, 2013
Escaping reserved URL characters
View NSString+URLCharacters.m
NSString *cleanedString = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)self, NULL, (CFStringRef)@"!#$&'()*+,/:;=?@[]", kCFStringEncodingUTF8));
return cleanedString;
View UIResponder+FirstResponder.h
#import "UIResponder+FirstResponder.h"
static __weak id currentFirstResponder;
@implementation UIResponder (FirstResponder)
+(id)currentFirstResponder {
currentFirstResponder = nil;
[[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil];
return currentFirstResponder;
You can’t perform that action at this time.