Skip to content

Instantly share code, notes, and snippets.

@PaulChana
PaulChana / SignSparkle.sh
Last active August 29, 2015 14:24
Sign Sparkle properly
# Run this as a post build script, immediately after you copy the sparkle bundle
LOCATION="${BUILT_PRODUCTS_DIR}"/"${FRAMEWORKS_FOLDER_PATH}"
IDENTITY="Idenitity" # Fill in with code sign identity
codesign --deep --verbose --force --sign "$IDENTITY" "$LOCATION/Sparkle.framework/Versions/A"
@PaulChana
PaulChana / CheckCodesign.sh
Last active August 29, 2015 14:24
Check code signing
codesign --verify --verbose=4 <PATH_TO_APP>
@PaulChana
PaulChana / SegControl.m
Last active August 29, 2015 14:24
Get segment of control clicked (NSSegmentedControl)
- (IBAction)doSomething:(id)sender {
NSSegmentedControl *control = (NSSegmentedControl *)sender;
NSInteger selectedSeg = [control selectedSegment];
// Do something!
}
@PaulChana
PaulChana / Literals.m
Last active August 29, 2015 14:24
Objective-C Literals
// Numbers
NSNumber *x = @(3.14);
// Arrays
NSArray *a = @[@"a", @"b", @"c"];
// Dictionary
NSDictionary *d = @{ @"key" : @"Loris",
@"name" : @"Joris",
@"n" : @"Boris" };
@PaulChana
PaulChana / ScrollNSTextView.m
Last active August 29, 2015 14:24
Scroll NSTextView to end
[_myTextView scrollRangeToVisible:NSMakeRange([[_myTextView string] length], 0)];
@PaulChana
PaulChana / StaticVarInit.m
Last active August 29, 2015 14:24
Static variable init
+ (NSColor *) staticColour {
__strong static NSColor* _sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [NSColor colorWithCalibratedRed:255.f green:255.f blue:255.f alpha:1.0];
});
return _sharedInstance;
}
@PaulChana
PaulChana / NSViewRemoveAllSubViews.m
Last active August 29, 2015 14:23
Clear All subviews of NSView
-(void)clearAllSubviewsOfView :(NSView *)parent {
for (NSView *subview in [parent subviews]) {
[subview removeFromSuperview];
}
}
@PaulChana
PaulChana / YosemiteTitlebar.m
Last active August 29, 2015 14:23
Yosemite title bar
window.titleVisibility = NSWindowTitleHidden;
@PaulChana
PaulChana / NSWindowControl.m
Last active August 29, 2015 14:23
Put a control in NSWindow titlebar
NSView *themeFrame = [[mainWindow contentView] superview];
NSRect c = [themeFrame frame];
NSRect aV = [accessoryView frame];
NSRect newFrame = NSMakeRect(c.size.width - aV.size.width,
c.size.height - aV.size.height,
aV.size.width,
aV.size.height);
[accessoryView setFrame:newFrame];
[themeFrame addSubview:accessoryView];
@PaulChana
PaulChana / OpenURL.m
Last active August 29, 2015 14:23
Open URL
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.google.com"]];