Skip to content

Instantly share code, notes, and snippets.

View jbrennan's full-sized avatar
😅
bestie please let me merge

Jason Brennan jbrennan

😅
bestie please let me merge
View GitHub Profile
@jbrennan
jbrennan / gist:1047140
Created June 26, 2011 02:03
Yo dawg, I heard you like Blocks
// Loads the full-sized image ... might be big.
- (void)originalImageWithCompletionHandler:(DownloadedImageCompletionHandler)completionHandler {
// First check to see if this image is cached in memory, if execute the handler passing in the image.
if (nil != _originalImage) {
if (completionHandler) {
completionHandler(self, _photo, _photo.urlOriginal, _originalImage);
}
@jbrennan
jbrennan / Bug.swift
Created July 16, 2015 14:03
Bug related to having an optional enum in a struct in Swift
import Foundation
public struct FeaturedItem {
public enum ImageSource {
case Bundled(name: String) // simplified enum with one case to illustrate the bug.
}
public let localizedTitleImageSource: ImageSource? // This optional causes Swift to barf. If it's non-optional, it compiles fine
// Workaround in this case is to just use an optional String instead of the enum.
}
@jbrennan
jbrennan / Elsewhere.swift
Created October 28, 2014 21:52
Generic UIViewController subclass
// usage
let pop = PopoverViewController<SomeViewController>()
self.showViewController(pop) // adds pop.view as a subview (stepping over this line reveals that pop.view becomes non-nil)
// -viewDidLoad is not called...
@jbrennan
jbrennan / boool.swift
Created September 2, 2014 20:37
Boooleans in Swift
typealias Boool = Bool? // Can be true, false, or nil
@implementation UIGestureRecognizer (ForDummies)
+ (instancetype)newWithView:(UIView *)view target:(id)target action:(SEL)action delegate:(id<UIGestureRecognizerDelegate>)delegate
{
UIGestureRecognizer *gesture = [[[self class] alloc] initWithTarget:target action:action];
gesture.delegate = delegate;
[view addGestureRecognizer:gesture];
view.userInteractionEnabled = YES;
return gesture;
@jbrennan
jbrennan / Emojis.m
Created June 19, 2014 20:42
Finding emojis in NSStrings
// This is bad and I feel bad. Suggestions for improvements on finding Emoji?
// This current solution is acceptable for us right now, but obviously the less I have to exclude the better.
@interface NSString (Emoji)
/**
Returns if the receiver may contain Emoji characters.
@note This method may have false-positives since it sees if the string has non-ASCII characters. If the receiver has a non-Emoji, non-ASCII character (like é) then it will still return YES.
*/