Skip to content

Instantly share code, notes, and snippets.

View justin's full-sized avatar

Justin Williams justin

View GitHub Profile
NSView *contentView = [self.window contentView];
self.button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 50.0f)];
[self.button setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.button setTitle:@"This is a test button"];
[self.button setBordered:YES];
[contentView addSubview:self.button];
NSButton *button = self.button;
@justin
justin / gist:2354923
Created April 10, 2012 22:01
NSObject+FancyDescription
#import <Foundation/Foundation.h>
@interface NSObject (FancyDescription)
//
// Output the values of all the properties associated with a given class.
// Iterates all the way down the chain until we hit NSObject.
//
- (NSString *)sg_description;
@justin
justin / gist:2354858
Created April 10, 2012 21:50
Description Sample
- (NSString *)description
{
return [NSString stringWithFormat:@"First = %@, Last = %@", self.firstName, self.lastName];
}
@justin
justin / gist:2340617
Created April 9, 2012 00:56
SGKeyboard Example
// Store a password
NSError *storePasswordError = nil;
BOOL passwordSuccessfullyCreated = [SGKeychain setPassword:@"testpassword" username:@"justin" serviceName:@"Twitter" updateExisting:NO error:&storePasswordError];
if (passwordSuccessfullyCreated == YES)
{
NSLog(@"Password successfully created");
}
else
{
@justin
justin / gist:2325877
Created April 7, 2012 06:23
Code Sign Entitlements Print Out
Bigham:Debug-iphoneos justin$ codesign -d --entitlements :/dev/stdout ./SGBlahExample.app
Executable=/Users/justin/Library/Developer/Xcode/DerivedData/SGBlahExample-eaniwkzkgbtjdidpkonkaycajvbh/Build/Products/Debug-iphoneos/SGBlahExample/SGBlahExample
<?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>application-identifier</key>
<string>PK266D9YNJ.secondgear.SGBlahExample</string>
<key>get-task-allow</key>
@justin
justin / gist:2315639
Created April 6, 2012 01:04
Remove UIWebView Shadows
for (UIView *view in self.webView.subviews)
{
if ([view isKindOfClass:[UIScrollView class]] == YES)
{
for (UIView *innerSubview in [view subviews])
{
if ([innerSubview isKindOfClass:[UIImageView class]])
{
innerSubview.hidden = YES;
}
@justin
justin / gist:2306582
Created April 4, 2012 23:36
Common Initializer Methods
- (id)init
{
if ((self = [super initWithNibName:nil bundle:nil]))
{
[self setup];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
@justin
justin / gist:2306549
Created April 4, 2012 23:29
Assert on initializers you aren't using
- (id)initWithDocument:(ELDocument *)document
{
if ((self = [super initWithNibName:nil bundle:nil]))
{
// Do your stuff in here.
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@justin
justin / gist:2299353
Created April 4, 2012 06:53
ARC Helper Macro Sample
- (id)initWithUserName:(NSString *)userName key:(NSString *)apiKey delegate:(id <SGMimiMailerDelegate>)delegate
{
if ((self = [super init]))
{
_userName = SG_RETAIN(userName);
_apiKey = SG_RETAIN(apiKey);
_delegate = delegate;
}
return self;
@justin
justin / gist:2298197
Created April 4, 2012 05:48
More ARC Helper Macros
#ifndef SG_WEAK
#if defined __IPHONE_OS_VERSION_MIN_REQUIRED
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3
#define __SG_WEAK __weak
#define SG_WEAK weak
#else
#define __SG_WEAK __unsafe_unretained
#define SG_WEAK unsafe_unretained
#endif
#elif defined __MAC_OS_X_VERSION_MIN_REQUIRED