Skip to content

Instantly share code, notes, and snippets.

View KevinVitale's full-sized avatar
👾
Game Boy

Kevin Vitale KevinVitale

👾
Game Boy
View GitHub Profile
@KevinVitale
KevinVitale / NeatKVOTrick.m
Created January 12, 2012 19:54
Neat KVO trick (when overriding @Property getters)
#pragma mark - Property Overrides
///-----------------------------
/// @name Property Overrides
///-----------------------------
- (UINavigationBar *)navigationBar {
if(!_navigationBar) {
[self willChangeValueForKey:@"navigationBar"];
_navigationBar = ^ {
CGRect frame = CGRectMake(0.f, 0.f, self.frame.size.width, 44.f);
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:frame];
@KevinVitale
KevinVitale / MyViewController.h
Created January 26, 2012 19:19
Automatically UIApplication notification observations when subclassing UIViewController
@interface MyViewController : UIViewController <UIApplicationDelegate> {
@private
NSMutableArray *_applicationObservers;
}
@end
@KevinVitale
KevinVitale / MenuSections.plist
Created February 2, 2012 16:24
MenuSections
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MenuSections</key>
<array>
<dict>
<key>Rows</key>
<array>
<dict>
@KevinVitale
KevinVitale / .gitignore
Created February 27, 2012 01:42
Xcode Gitignore
# Profiling
#################
Instruments
# Textmate Files #
##################
*.tmproj
# Xcode 4 Files #
#################
@KevinVitale
KevinVitale / gist:1926942
Created February 27, 2012 20:51
Building Universal Binaries (iOS)
# taken from: http://bit.ly/qRA6DX
#
# Version 2.0 (updated for Xcode 4, with some fixes)
# Changes:
# - Works with xcode 4, even when running xcode 3 projects (Workarounds for apple bugs)
# - Faster / better: only runs lipo once, instead of once per recursion
# - Added some debugging statemetns that can be switched on/off by changing the DEBUG_THIS_SCRIPT variable to "true"
# - Fixed some typos
#
# Purpose:
@protocol MyProtocol <NSObject>
@optional
- (void)myClassObject:(MyClass *)myObject didFinishWithResult:(id)result;
@required
- (void)myClassObject:(MyClass *)myObject willBeingToInitialize;
@end
@interface MyClass : NSObject <MyProtocol>
- (void)doSomething;
@KevinVitale
KevinVitale / Keychain+CF+Arc.m
Created June 5, 2012 20:27
Does this leak in ARC?
NSArray *resultArray = nil;
CFTypeRef inTypeRef = (__bridge CFTypeRef)resultArray;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &inTypeRef);
@KevinVitale
KevinVitale / AgeChecker.m
Created December 14, 2012 19:40
Mixes C stdin with Obj-C; uses new literal syntax
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, assign, readonly) NSString *fullName;
@property (nonatomic, strong) NSNumber *age;
- (id)initWithFirstName:(NSString *)firstName lastName:(NSString *)lastName;
@end
@KevinVitale
KevinVitale / gist:4322987
Created December 17, 2012 22:30
Example of a class defining a property which is a block type
#import <Foundation/Foundation.h>
@interface Blocky : NSObject
@property (nonatomic, strong) void (^block)(void);
@end
@implementation Blocky
@end
int main(int argc, char *argv[]) {
void hsl_to_hsv(float hh, float ss, float ll,
float* h, float* s, float *v)
{
*h = hh;
ll *= 2;
ss *= (ll <= 1) ? ll : 2 - ll;
*v = (ll + ss) / 2;
*s = (2 * ss) / (ll + ss);
}