Skip to content

Instantly share code, notes, and snippets.

View AtomicCat's full-sized avatar

Dave Camp AtomicCat

  • Forest Grove, or
View GitHub Profile
//
// SDMacros.h
// walmart
//
// Created by Brandon Sneed on 7/11/13.
// Copyright (c) 2013 Walmart. All rights reserved.
//
/**
The __deprecated__ macro saves a little bit of typing around marking classes and methods as deprecated.
@AtomicCat
AtomicCat / gist:5166194
Created March 14, 2013 23:27
Ugly way to call super from a weak self
#import <Foundation/Foundation.h>
#import <objc/objc-runtime.h>
@interface Foo : NSObject
@end
@implementation Foo
@AtomicCat
AtomicCat / gist:5001293
Created February 21, 2013 01:51
Class fun
#import <Foundation/Foundation.h>
#import <objc/objc.h>
#import <objc/runtime.h>
#import <objc/message.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
Class stringClass = [NSString class];
NSLog(@"foo: %@", objc_msgSend(stringClass, @selector(stringWithFormat:), @"bar"));
}
@AtomicCat
AtomicCat / UIView+FrameAdditions.h
Created August 22, 2012 17:08 — forked from nfarina/UIView+FrameAdditions.h
UIView Frame helper getter/setter category methods
#import <UIKit/UIKit.h>
@interface UIView (SMFrameAdditions)
@property (nonatomic, assign) CGPoint $origin;
@property (nonatomic, assign) CGSize $size;
@property (nonatomic, assign) CGFloat $x, $y, $width, $height; // normal rect properties
@property (nonatomic, assign) CGFloat $left, $top, $right, $bottom; // these will stretch the rect
@end
@AtomicCat
AtomicCat / gist:1407621
Created November 30, 2011 01:57
UIView (NibLoadingExtension)
@implementation UIView (NibLoadingExtension)
+ (id)viewFromNib
{
static NSMutableDictionary *caches = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
caches = [[NSMutableDictionary dictionary] retain];
});
@AtomicCat
AtomicCat / gist:1220903
Created September 16, 2011 00:46
numeric comparison
NSCharacterSet *stripSet = [NSCharacterSet characterSetWithCharactersInString:@"."];
val1 = [[val1 componentsSeparatedByCharactersInSet:stripSet] componentsJoinedByString:@""];
val2 = [[val2 componentsSeparatedByCharactersInSet:stripSet] componentsJoinedByString:@""];
return [val1 compare:val2 options:NSNumericSearch | NSCaseInsensitiveSearch];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void)
{
// take snapshot of main view to fake background
//
// start with a vertical slice of the middle, slightly taller than modal
//
// translate & clip layer before rendering for performance
//
static char *kMyAssociationKey = nil;
- (void)setContext:(id)context
{
objc_setAssociatedObject(self, &kMyAssociationKey, context, OBJC_ASSOCIATION_ASSIGN);
}
- (id)context
{
return objc_getAssociatedObject(self, &kMyAssociationKey);
@interface MyClass ()
@property (nonatomic, retain) NSArray *myInternalArray;
@property (nonatomic, retain) UIImage *myInternalImage;
@end
@implementation MyClass
@synthesize myInternalArray;