This file contains hidden or 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
func staticInsideFunction() { | |
struct Temp { static var hasAnimated = false } | |
if Temp.hasAnimated == false { | |
// ... do something only on the first function call. | |
Temp.hasAnimated = true | |
} else { | |
// ... do something on all subsequent function calls. | |
} | |
} |
This file contains hidden or 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 (indexPath.section, indexPath.row) { | |
case (0, _): println("section 0") | |
case (1, _): println("section 1") | |
case (2, 0...2): println("section 2 0-2") | |
case (2, 3...5): println("section 2 3-5") | |
case (3, let row): println("\(row)") | |
default: println("") | |
} |
This file contains hidden or 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
// | |
// NSObject+LUBDescription.h | |
// | |
// Created by Bryan Luby on 5/5/14. | |
// Copyright (c) 2014 Bryan Luby. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (LUBDescription) |
This file contains hidden or 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
@interface CustomObject () | |
@property (strong, nonatomic) NSMutableDictionary *arbitraryKeyValuePairs; | |
@end | |
@implementation CustomObject | |
- (void)setValue:(id)value forUndefinedKey:(NSString *)key | |
{ | |
if (!self.arbitraryKeyValuePairs) { | |
self.arbitraryKeyValuePairs = [NSMutableDictionary dictionary]; |
This file contains hidden or 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
@implementation CALayer (NibAccess) | |
- (void)setLub_borderColor:(UIColor *)color | |
{ | |
self.borderColor = color.CGColor; | |
} | |
- (UIColor *)lub_borderColor | |
{ | |
return [UIColor colorWithCGColor:self.borderColor]; |
This file contains hidden or 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)handleKeyboardShow:(NSNotification *)notification | |
{ | |
NSDictionary *dict = notification.userInfo; | |
NSValue *rectValue = dict[UIKeyboardFrameEndUserInfoKey]; | |
CGRect keyboardRect = [rectValue CGRectValue]; | |
UITextView *activeTextView; | |
if ([self.textView1 isFirstResponder]) { | |
activeTextView = self.textView1; | |
} else if ([self.textView2 isFirstResponder]) { |
This file contains hidden or 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
// Make sure viewDidAppear has happened before sending this action to ensure that all links | |
// in the responder chain are connected. | |
// http://stackoverflow.com/a/11768282/1306872 | |
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) | |
to:nil | |
from:nil | |
forEvent:nil]; | |
This file contains hidden or 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
// http://stackoverflow.com/a/4242037/1306872 | |
- (void)inspectResponderChainFromSender:(id)sender | |
{ | |
if ([sender isKindOfClass:[UIResponder class]]) { | |
NSMutableArray *responderChain = [NSMutableArray array]; | |
[responderChain insertObject:sender atIndex:0]; | |
while ((sender = [sender nextResponder])) { | |
if ([sender nextResponder]) { |
This file contains hidden or 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+Reversed.h | |
// | |
// Created by Bryan Luby on 5/16/13. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSString (Reversed) |
NewerOlder