View ReusableCellExample.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
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = | |
[tableView dequeueReusableCellWithIdentifier:REUSABLE_CELL_ID]; | |
UILabel *label = (UILabel *)[cell viewWithTag:VIEW_TAG]; | |
Model *someModel = [self getModelFromIndexPath:indexPath]; | |
// `takeUntil:` makes the RACObserve() signal complete (and thus breaks the subscription) | |
// when the cell is recycled. |
View gist:3526cac1682c7d165c42
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
/** | |
Provides the ability to verify key paths at compile time. | |
If "keyPath" does not exist, a compile-time error will be generated. | |
Example: | |
// Verifies "isFinished" exists on "operation". | |
NSString *key = SQKeyPath(operation, isFinished); | |
// Verifies "isFinished" exists on self. |
View DrawView.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
/* | |
Copied and pasted from David Hamrick's blog. | |
Source: http://www.davidhamrick.com/2011/08/07/using-blocks-for-drawing-to-avoid-subclasssing-in-objective-c.html | |
*/ | |
typedef void(^DrawView_DrawBlock)(UIView* v,CGContextRef context); | |
@interface DrawView : UIView |
View gist:1830844
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
/* | |
Copied and pasted from Tim Oliver's blog. | |
Source: http://www.tim-oliver.com/2011/10/23/creating-the-uitableview-bevel-effect-in-coregraphics/ | |
*/ | |
void DrawInsetBeveledRoundedRect(CGContextRef context, CGRect rect, CGFloat radius, UIColor *fillColor) { | |
//contract the bounds of the rectangle in to account for the stroke | |
CGRect drawRect = CGRectInset(rect, 1.0f, 1.0f); | |
//contract the height by 1 to account for the white bevel at the bottom |
View debug.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
// via @_bejo | |
// then just add a DEBUG = 1 to debug target in xcode | |
#ifdef DEBUG | |
#define DebugLog( s, ... ) NSLog( @"<%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#else | |
#define DebugLog( s, ... ) |
View gist:1869980
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
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
Note: setting view.layer.cornerRadius and .masksToBounds | |
sends the view for rending to an offscreen buffer. | |
We want to avoid unnecessary rendering passes. | |
Let the context do the work. | |
*/ | |
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { | |
CGRect rect = layer.bounds; |
View gist:2152929
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
/* | |
Thanks to @_bejo | |
*/ | |
- (void)_insertGlobalRoomMessage:(id)msg atIndex:(NSUInteger)index | |
{ | |
NSIndexSet *changeSet = [NSIndexSet indexSetWithIndex:index]; | |
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:changeSet forKey:@"globalRoomMessages"]; | |
[(NSMutableArray *)self.globalRoomMessages insertObject:msg atIndex:index]; | |
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:changeSet forKey:@"globalRoomMessages"]; |
View .gitignore
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
# .gitignore in use by Joris Kluivers | |
# | |
# Latest version: | |
# https://gist.github.com/gists/1923197 | |
*.DS_Store | |
# Xcode | |
*.pbxuser | |
*.mode1v3 |
View gist:3689409
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
/* | |
Enum with Fixed Underlying Type | |
New with Xcode 4.4 | |
Via WWDC2012 Session 405 - Modern Objective-C | |
Results in better code completion and stronger type checking. | |
Use -Wconversion compiler flag to check for enum type errors. | |
-Wswitch for checking if switch statement is fully handled for enum. | |
*/ |
View gist:3689574
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
/* | |
Source: WWDC2012 Modern Objective-C talk | |
How to get a constant literal container to work. | |
*/ | |
@implementation MyClass | |
static NSArray *thePlanets; | |
+ (void)initialize { |
OlderNewer