Skip to content

Instantly share code, notes, and snippets.

@aegzorz
aegzorz / NSArray+FirstObject.h
Last active November 27, 2021 06:58
Gets the first object in an array or returns nil for empty array.
//
// NSArray+FirstObject.h
//
#import <Foundation/Foundation.h>
@interface NSArray (FirstObject)
- (id)firstObject;
@aegzorz
aegzorz / NSObject+LogDealloc.h
Last active October 16, 2021 13:08
Category on NSObject that logs deallocs, useful when tracking down memory leaks
#import <Foundation/Foundation.h>
@interface NSObject (LogDealloc)
- (void)logOnDealloc;
@end
@aegzorz
aegzorz / UIView+Recursion.h
Created July 11, 2013 10:40
Recursively find a subview.
#import <UIKit/UIKit.h>
@interface UIView (Recursion)
/**
Return YES from the block to recurse into the subview.
Set stop to YES to return the subview.
*/
- (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse;
@aegzorz
aegzorz / CGRect+Additions.h
Created June 17, 2013 14:35
Some functions for dealing with CGRects
static __inline__ CGRect CGRectFromCGSize( CGSize size ) {
return CGRectMake( 0, 0, size.width, size.height );
};
static __inline__ CGRect CGRectMakeWithCenterAndSize( CGPoint center, CGSize size ) {
return CGRectMake( center.x - size.width * 0.5, center.y - size.height * 0.5, size.width, size.height );
};
static __inline__ CGRect CGRectMakeWithOriginAndSize( CGPoint origin, CGSize size ) {
return CGRectMake( origin.x, origin.y, size.width, size.height );
UIImage* image = GetImageWithID( kImageResourcesImagesMyImage );
UIImage* image = [UIImage imageNamed:@"resources/images/my-image.png"];
static NSString* __AppResources[] = {
@"resources/images/my-image.png",
@"resources/images/my-image2.png",
@"resources/images/subfolder/my-image.png",
@"resources/test.pdf",
nil
};
static const NSUInteger kImageResourcesImagesMyImage = 0;
static const NSUInteger kImageResourcesImagesMyImage2 = 1;
@aegzorz
aegzorz / gist:2846024
Created May 31, 2012 20:33
Generating resource IDs
header_subpath = "Resources.h"
resource_categories = {
".pdf" => "File",
".png" => "Image",
".jpg" => "Image"
}
def wikify(phrase)
phrase = phrase.tr( "-", " " ).tr( "_", " " ).tr( "/", " " )
UIImageDrawBlock draw = ^( CGContextRef ctx, CGRect rect ) {
[[UIColor redColor] setFill];
[[UIBezierPath bezierPathWithRect:rect] fill];
};
UIImage* texture = [UIImage imageWithSize:CGSizeMake( 100, 100 ) opaque:NO scale:1.0 draw:draw];
@aegzorz
aegzorz / UIImage+Additions.h
Created May 30, 2012 17:19
UIImage+Additions.h
typedef void (^UIImageDrawBlock)( CGContextRef ctx, CGRect rect );
@interface UIImage (Additions)
+ (UIImage*)imageWithSize:(CGSize)size opaque:(BOOL)opaque scale:(CGFloat)scale draw:(UIImageDrawBlock)draw;
@end