Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / ScrollNSTextView.m
Last active August 29, 2015 14:24
Scroll NSTextView to end
[_myTextView scrollRangeToVisible:NSMakeRange([[_myTextView string] length], 0)];
@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 / 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 / CheckCodesign.sh
Last active August 29, 2015 14:24
Check code signing
codesign --verify --verbose=4 <PATH_TO_APP>
@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 / AutoDMG.sh
Last active July 4, 2023 21:50
Make a DMG auto open
dmg_vol_name="name"
dmg_path="/path/to/final/dmg/$dmg_vol_name.dmg" # Final DMG that you will be shipping
dmg_build_path="/path/to/temp/dmg/$dmg_vol_name.dmg" # Temporary DMG that will be worked on and then deleted
dmg_volume="/Volumes/$dmg_vol_name" # Should match the mounted name of your DMG. Be sensible and make it the name ;-P
hdiutil attach -owners on "dmg_build_path" -shadow
bless "$dmg_volume/" --openfolder "$dmg_volume" # This actually makes the change to auto open the DMG in finder
hdiutil detach "$dmg_volume"
hdiutil convert -format UDZO -o "$dmg_path" "$dmg_build_path" -shadow
@PaulChana
PaulChana / NSButtonDownDraw.m
Last active August 29, 2015 14:25
Is NSButton in down state during drawing
- (void)drawRect:(NSRect)dirtyRect {
if ([self isHighlighted]) {
// Mouse is down
}
else {
// Nope, mouse is either down and outside our area, or not down
}
}
@PaulChana
PaulChana / StringToURL.m
Created July 22, 2015 20:54
NSString path to NSURL
[NSURL fileURLWithPath:nsstringPath];