Skip to content

Instantly share code, notes, and snippets.

View tonyarnold's full-sized avatar

Tony Arnold tonyarnold

View GitHub Profile
@tonyarnold
tonyarnold / UpdatePrefsLocation.m
Created January 22, 2011 06:23
Need to migrate your preferences from an existing bundle ID? Use this in your App Delegate.
+ (void)initialize {
// Update the preferences location from the old location (which is now used for the App Store)
NSDictionary *retailUserDefaults = [[NSUserDefaults standardUserDefaults] persistentDomainForName:[NSApp applicationIdentifier]];
if (retailUserDefaults == nil) {
NSDictionary *macAppStoreUserDefaults = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.thecocoabots.hyperspaces"];
for (NSString *key in [macAppStoreUserDefaults allKeys]) {
[[NSUserDefaults standardUserDefaults] setObject:[macAppStoreUserDefaults objectForKey:key] forKey:key];
}
@tonyarnold
tonyarnold / gist:897561
Created April 1, 2011 00:54
So System Events is always available via the Scripting Bridge first thing on startup. This is nasty, but it works.
SomeClass *someObj = nil;
// This is a rude and nasty hack. Basically if someObj is nil, just keep checking until you get it.
while (someObj == nil) {
someObj = [AppDelegate sharedAppDelegate].somethingIWantFromSystemEvents;
if (someObj == nil) {
CBLog(@"Could not get a hold of the thing I wanted from System Events.app. Sleeping for 2 seconds before trying again.");
sleep(2);
}
@tonyarnold
tonyarnold / gist:1185353
Created September 1, 2011 03:17
Xcode Project Organisation
Project Folder:
AppName
→ Classes
→ MyGreatClass.m
→ MyGreatClass.h
→ …
→ Model
@tonyarnold
tonyarnold / gist:1379451
Created November 19, 2011 22:21
Xcode build script to highlight TODO/FIXME/???/!!! in build logs, while excluding certain directories
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -path "${SRCROOT}/Vendor" -or -path "${SRCROOT}/.git" \) -prune -o \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@tonyarnold
tonyarnold / NASpinSegue.m
Created December 4, 2011 04:09 — forked from neilang/NASpinSegue.m
Spin Segue
#import "NASpinSegue.h"
@implementation NASpinSegue
- (void)perform{
UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *)self.destinationViewController;
@tonyarnold
tonyarnold / gist:2010649
Created March 10, 2012 07:22
Exhaustively check if an Objective-C object is "empty"
static inline BOOL CBIsEmpty(id obj) {
return obj == nil
|| (NSNull *)obj == [NSNull null]
|| ([obj respondsToSelector:@selector(length)] && [obj length] == 0)
|| ([obj respondsToSelector:@selector(count)] && [obj count] == 0);
}
@tonyarnold
tonyarnold / gist:2484539
Created April 24, 2012 23:22
A crashy piece of code under ARC
- (void)dwk_postChangeNotification:(NSString *)notificationName newValue:(id)newValue oldValue:(id)oldValue
{
if (CBIsEmpty(newValue) || CBIsEmpty([self fileModificationDate])) {
return;
}
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:2];
[userInfo setObject:newValue forKey:kNotificationOldValueKey];
@tonyarnold
tonyarnold / Peekaboo.h
Created May 15, 2012 07:11
How do i call a parent ViewController's method?
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface Peekaboo : UIView
@property (nonatomic, retain) ViewController *parentView;
- (void) show;
@end
ROFL:ROFL:LOL:ROFL:ROFL
______ / \______
L / \
L O L====== \__
L \________________________|
H H
/==============/
@tonyarnold
tonyarnold / NSScreen+CBAdditions.h
Created June 8, 2012 02:52
Retrieve the frame of the OS X desktop as a single NSRect
//
// NSScreen+CBAdditions.h
// Hyperspaces
//
// Created by Tony Arnold on 2/11/10.
// Copyright 2010 The CocoaBots. All rights reserved.
//
#import <Cocoa/Cocoa.h>