Skip to content

Instantly share code, notes, and snippets.

@MattFoley
MattFoley / gist:4945666
Created February 13, 2013 16:08
Helpful PCH Macros.
#define screenHeight() ([UIScreen mainScreen].bounds.size.height)
#define isPhoneFive() (screenHeight() == 568)
#define isOS6() ([[[UIDevice currentDevice] systemVersion]intValue] > 5.2)
#define UIInterfaceIdiomIsPad() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
@MattFoley
MattFoley / gist:5222512
Created March 22, 2013 16:06
Literal Syntax Magic: Not only can literal syntax do assignment, creation, and re-assignment; it can also do addObject:
NSMutableArray *objects = [@[] mutableCopy];
NSObject *someObject = [NSObject new];
objects[objects.count] = object;
@MattFoley
MattFoley / Remove Webviews
Created April 25, 2013 15:00
Removing Webview Shadows.
- (void)removeShadows
{
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
for(UIView *view in self.subviews){
if ([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
if ([view isKindOfClass:[UIScrollView class]]) {
@MattFoley
MattFoley / gist:5601191
Created May 17, 2013 18:58
UIColorFromRGB, call like "UIColorFromRGB(0xFFFFFF)"
//Function to convert RGB values into Hexadecimal/Base16
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@MattFoley
MattFoley / gist:5605869
Created May 18, 2013 21:40
Write Console to File iOS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
@MattFoley
MattFoley / gist:5621517
Created May 21, 2013 17:19
Number pad Go Button, animation mimicking.
- (void)setupDecimalPadDone
{
self.keyboardShownObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
self.goButton = [UIButton buttonWithType:UIButtonTypeCustom];
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:self.goButton];
@MattFoley
MattFoley / gist:5809644
Created June 18, 2013 21:33
Reset Core Data
- (void)resetCoreData
{
NSArray *stores = [self.persistentStoreCoordinator persistentStores];
for(NSPersistentStore *store in stores) {
[self.persistentStoreCoordinator removePersistentStore:store error:nil];
[[NSFileManager defaultManager] removeItemAtPath:store.URL.path error:nil];
}
_persistentStoreCoordinator = nil;
@MattFoley
MattFoley / gist:5809710
Created June 18, 2013 21:41
Logout wait for synchronous network requests.
dispatch_async(dispatch_get_main_queue(), ^{
[self.dialog setTitleString:@"Logging Out..."];
<Show Dialog>
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
#warning This would be better if our Network Utility ran off of the delegate protocol so we could cancel Network Requests.
do {
usleep(NSEC_PER_MSEC);
@MattFoley
MattFoley / gist:5851687
Created June 24, 2013 17:06
Pan direction recognizer.
CGPoint velocity = [panGesture velocityInView:panGesture.view];
if (MAX(ABS(velocity.y), ABS(velocity.x)) == ABS(velocity.y) ) {
//Significant direction is vertical
if (velocity.y > 0) {
//Going Down
NSLog(@"Down");
} else {
NSLog(@"Up");
//Going Up
@MattFoley
MattFoley / gist:5867812
Created June 26, 2013 14:29
Core data weirdness.
self.group = [EVGroup fetchForPredicate:predicate
- forManagedObjectContext:self.group.managedObjectContext];