Skip to content

Instantly share code, notes, and snippets.

View andrewgarn's full-sized avatar

Andrew Garn andrewgarn

View GitHub Profile
@mattt
mattt / nshipster-new-years-2015.md
Created November 25, 2014 19:38
NSHipster New Year's 2015

Season's Greetings, NSHipsters!

As the year winds down, and we take a moment to reflect on our experiences over the past months, one thing is clear: 2014 has been an incredible year professionally for Apple developers. So much has happened in such a short timespan, and yet it's hard to remember our relationship to Objective-C before Swift, or what APIs could have captivated our imagination as much as iOS 8 or WatchKit.

It's an NSHipster tradition to ask you, dear readers, to send in your favorite tips and tricks from the past year for publication over the New Year's holiday. This year, with the deluge of new developments—both from Cupertino and the community at large—there should be no shortage of interesting tidbits to share.

Submit your favorite piece of Swift or Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

If you're wondering about what to post, look to

@nicklockwood
nicklockwood / NSCacheFix.m
Last active December 31, 2015 18:18
NSCache seems to be broken in iOS 7 - it doesn't empty itself, even if your app runs out of memory. This is a simple category to fix the problem.
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@implementation NSCache (Fix)
+ (void)load
{
//swizzle init
Method a = class_getInstanceMethod(self, @selector(init));
@mikeash
mikeash / runtime-class.m
Created November 22, 2013 16:46
Creating a usable class purely at runtime using the Objective-C runtime APIs.
// clang -fobjc-arc -framework Foundation runtime-class.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Person : NSObject
- (id)initWithFirstName: (NSString *)firstName lastName: (NSString *)lastName age: (NSUInteger)age;

Greetings, NSHipsters!

As we prepare to increment our NSDateComponents -year by 1, it's time once again for NSHipster end-of-the-year Reader Submissions! Last year, we got some mind-blowing tips and tricks. With the release of iOS 7 & Mavericks, and a year's worth of new developments in the Objective-C ecosystem, there should be a ton of new stuff to write up for this year.

Submit your favorite piece of Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

Here are a few examples of the kind of things I'd like to see:

  • Using NSStringFromSelector(@selector()) as a safer way to do KVC / KVO / NSCoding.
  • Panic's [rather surprising discovery about the internals of the Lightning Digital AV Adapter](http://www.panic.com/blog/the-lightning-di
@0xced
0xced / NSObject+Subclasses.h
Last active September 4, 2017 06:37
NSObject category to get subclasses
#import <Foundation/Foundation.h>
@interface NSObject (Subclasses)
+ (NSSet *) subclasses_xcd;
@end
@steipete
steipete / AppDelegate.m
Last active December 13, 2015 17:29
Hook onto NSNotificationCenter to see all notifications.
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"%@: %@", note.name, note.userInfo);
}];
@lessthanyouthink
lessthanyouthink / CJProperRotationNavigationController.h
Created October 5, 2012 20:27
A simple UINavigationController subclass to handle iOS 6's orientation changes better.
//
// CJProperRotationNavigationController.h
//
// Created by Charles Joseph on 2012-10-01.
//
#import <UIKit/UIKit.h>
@interface CJProperRotationNavigationController : UINavigationController
@0xced
0xced / XCDFakeCarrier.m
Last active March 5, 2023 22:07
Hack to choose the displayed carrier name in the iOS simulator
//
// Copyright (c) 2012-2015 Cédric Luthi / @0xced. All rights reserved.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_SIMULATOR
static const char *fakeCarrier;
static const char *fakeTime;
@danielpunkass
danielpunkass / gist:2854083
Created June 1, 2012 18:06
Zsh functions for easily "fixing" iOS-optimized PNG files
function fixpng ()
{
if [[ ! -f $1 ]] ; then
echo "Usage: fixpng <inputFiles> [outputFile]"
return -1
else
local inputFile=$1
local outputFile=$1
if [[ -e $2 ]] ; then
outputFile=$2
@nicklockwood
nicklockwood / ARCHelper.h
Last active November 20, 2018 10:02
ARC Helper
//
// ARC Helper
//
// Version 2.2
//
// Created by Nick Lockwood on 05/01/2012.
// Copyright 2012 Charcoal Design
//
// Distributed under the permissive zlib license
// Get the latest version from here: