Skip to content

Instantly share code, notes, and snippets.

View danmartyn's full-sized avatar

Daniel Martyn danmartyn

  • Ceridian
  • Canada
View GitHub Profile
@danmartyn
danmartyn / stringify
Created September 24, 2013 18:26
Encode and Decode objects without making typos
Taken From: http://stablekernel.com/blog/speeding-up-nscoding-with-macros/
#define OBJC_STRINGIFY(x) @#x
#define encodeObject(x) [aCoder encodeObject:x forKey:OBJC_STRINGIFY(x)]
#define decodeObject(x) x = [aDecoder decodeObjectForKey:OBJC_STRINGIFY(x)]
#define encodeFloat(x) [aCoder encodeFloat:x forKey:OBJC_STRINGIFY(x)]
#define decodeFloat(x) x = [aDecoder decodeFloatForKey:OBJC_STRINGIFY(x)]
- (id)initWithCoder:(NSCoder *)aDecoder
{
@danmartyn
danmartyn / GCD
Created October 15, 2013 04:18
Typical use case for GCD
// Doing something on the main thread
dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
dispatch_async(myQueue, ^{
// Perform long running process
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
});