Skip to content

Instantly share code, notes, and snippets.

@paulofierro
Last active August 29, 2015 13:55
Show Gist options
  • Save paulofierro/8735487 to your computer and use it in GitHub Desktop.
Save paulofierro/8735487 to your computer and use it in GitHub Desktop.
Xcode snippets that I always forget how to type.

Block properties

@property (nonatomic, copy) void (^myBlock)(void);
@property (nonatomic, copy) void (^myBlock)(NSString *parameter);

Block variables

void (^myBlock)() = ^()
{
    NSLog(@"Do something");
};

void (^myBlock)(NSString *) = ^(NSString *parameter)
{
    NSLog(@"Do something with %@", parameter);
};

Weak / Strong self references

__weak __typeof__(self) weakSelf = self;
__typeof__(self) strongSelf = weakSelf;

DLog

#ifdef DEBUG
#define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) {NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__]);[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__];}
#else
#define DLog(...) do { } while (0)
#define ALog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#endif

Symbolic breakpoints

-[NSObject(NSObject) doesNotRecognizeSelector:]

Kill Preferences daemon (OS X dev)

ps auwx | grep cfprefsd | grep -v grep | awk '{print $2}' | xargs sudo kill -9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment