View testimage.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View UIView+Snapshots.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View Coalescing in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func coalesce<T>(args: T?...) -> T? { | |
for possible in args { | |
if let actual = possible { | |
return actual | |
} | |
} | |
return nil | |
} |
View gist:89ce72a87e1b0661eccb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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]; |
View UIImageOrientation to TIFF orientation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch (originalOrientation) | |
{ | |
case UIImageOrientationUp: | |
orientationValue = @1; | |
break; | |
case UIImageOrientationDown: | |
orientationValue = @3; | |
break; | |
case UIImageOrientationLeft: | |
orientationValue = @8; |
View gist:6881601
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
fi |
View gist:6364558
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)themeBackButtons | |
{ | |
// 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(UIImage*)tintedMonoImageWithColor:(UIColor*)color | |
{ | |
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f); | |
[color setFill]; | |
CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height); | |
UIRectFill(bounds); | |
[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0]; | |
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); |
View NSString+URLCharacters.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSString*)stringByPercentEscapingReservedURLCharacters | |
{ | |
NSString *cleanedString = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)self, NULL, (CFStringRef)@"!#$&'()*+,/:;=?@[]", kCFStringEncodingUTF8)); | |
return cleanedString; | |
} |
View UIResponder+FirstResponder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
NewerOlder