Skip to content

Instantly share code, notes, and snippets.

View jrturton's full-sized avatar

Richard Turton jrturton

View GitHub Profile
@jrturton
jrturton / UIImageOrientation to TIFF orientation
Created February 27, 2014 11:35
Converting UImageOrientation to TIFF orientation values
switch (originalOrientation)
{
case UIImageOrientationUp:
orientationValue = @1;
break;
case UIImageOrientationDown:
orientationValue = @3;
break;
case UIImageOrientationLeft:
orientationValue = @8;
@jrturton
jrturton / gist:89ce72a87e1b0661eccb
Created October 2, 2014 13:30
Removing a core data store
-(void)removeDataStoreAtURL:(NSURL*)url
{
// 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];
import Foundation
func coalesce<T>(args: T?...) -> T? {
for possible in args {
if let actual = possible {
return actual
}
}
return nil
}
import UIKit
// Snapshot utilities
extension UIView {
func snapshotView(view: UIView, afterUpdates: Bool) -> UIView {
let snapshot = view.snapshotViewAfterScreenUpdates(afterUpdates)
self.addSubview(snapshot)
snapshot.frame = convertRect(view.bounds, fromView: view)
return snapshot
@jrturton
jrturton / testimage.swift
Created November 19, 2018 14:59
Make a date-stamped test image
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 400, height: 400))
let image = renderer.image {
context in
UIColor.lightGray.setFill()
UIRectFill(context.format.bounds)
UIColor.black.set()
UIRectFrame(context.format.bounds)
let text = "TEST IMAGE \n\(Date())" as NSString
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center