Skip to content

Instantly share code, notes, and snippets.

@drance
drance / gist:4546014
Created January 16, 2013 09:57
Workaround to vanilla UICollectionView+UICollectionViewFlowLayout using non-integral origins, leading to blurry cells.
@implementation BHSCollectionViewFlowLayout
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *allAttrs = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in allAttrs) {
attributes.frame = CGRectIntegral(attributes.frame);
}
return allAttrs;
}
@MugunthKumar
MugunthKumar / ARCError.m
Created August 17, 2012 03:22
ARC error
#if ! __has_feature(objc_arc)
#error This file/class is targeted for the ARC compiler. Either turn on ARC for your project or use -fobjc-arc flag
#endif
@krzysztofzablocki
krzysztofzablocki / gist:3240133
Created August 2, 2012 19:58
Handling dial like rotation on CCNode by using UIPanGestureRecognizer
//! for gesture recognizer support in cocos2d use https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers
- (void)handlePanGesture:(UIPanGestureRecognizer*)gestureRecognizer
{
CGPoint location = [[CCDirector sharedDirector] convertToGL:[gestureRecognizer locationInView:gestureRecognizer.view]];
static CGPoint oldLocation;
//! this will make sure that oldLocation is initialized
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
//! we need to calculate angle difference between previous position and current one in regards to dial center
CGPoint firstDir = ccpSub(oldLocation, dial.position);
@tonyarnold
tonyarnold / NSUserDefaultsObjectSubscripting.h
Created July 29, 2012 07:51
Add simple object subscripting to NSUserDefaults
//
// NSUserDefaults+ObjectSubscripting.h
//
// Created by Tony Arnold on 29/07/12.
// Copyright (c) 2012 The CocoaBots. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSUserDefaults (ObjectSubscripting)
@eoghain
eoghain / MYJSONSerilization
Created July 17, 2012 23:19
NSJSONSerilization compatibility using SBJSON (json-framework) for < iOS5 compatibility kinda
#import "SBJson.h"
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface MYJSONSerialization : NSObject
+ (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error;
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;
@end
@hollance
hollance / Explanation.md
Last active September 25, 2017 03:35
Communicate between objects using channels

Communicate between objects using channels

When you have two objects A and B, say two view controllers, that you want to have talk to each other, you can choose from the following options:

  • NSNotificationCenter. This is anonymous one-to-many communication. Object A posts a notification to the NSNotificationCenter, which then distributes it to any other objects listening for that notification, including Object B. A and B do not have to know anything about each other, so this is a very loose coupling. Maybe a little too loose...

  • KVO (Key-Value Observing). One object observes the properties of another. This is a very tight coupling, because Object B is now peeking directly into Object A. The advantage of KVO is that Object A doesn't have to be aware of this at all, and therefore does not need to send out any notifications -- the KVO mechanism takes care of this behind the scenes.

  • Direct pointers. Object A has a pointer to Object B and directly sends it messages when something of interest h

@jinthagerman
jinthagerman / UIColor+Addition.m
Created May 16, 2012 05:26
UIColor from hex
// http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string
+ (UIColor *) colorWithHex:(int)hex {
return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0
green:((float)((hex & 0xFF00) >> 8))/255.0
blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
}