$30 off During Our Annual Pro Sale. View Details »

What I Learned From AFNetworking's GitHub Issues

What I Learned From AFNetworking's GitHub Issues

(Presented at NYC iOS Developer Meetup & CocoaConf Columbus 2012)

It can be said that GitHub Issues are the hacker's equivalent of the classical Greek forum. Like the ancient philosophers before us, here the leading minds in open source gather to discuss the programming topics of our day. In this talk, we'll dig through AFNetworking's backlog to discover and dissect the epic debates, lofty ideas, and occasionally-fierce rhetorical exchanges contained within those hallowed threads.

Mattt Thompson

August 11, 2012
Tweet

More Decks by Mattt Thompson

Other Decks in Programming

Transcript

  1. • Ordered Query String Parameters • Customizable Query String Format

    • Property for DELETE Parameters to be in either Query String or Message Body • Retry Parameter for Operations • Option to Parse Top-Level JSON Fragments
  2. NSData * AFJSONEncode(id object, NSError **error) { NSData *data =

    nil; SEL _JSONKitSelector = NSSelectorFromString(@"JSONDataWithOptions:error:"); SEL _YAJLSelector = NSSelectorFromString(@"yajl_JSONString"); id _SBJsonWriterClass = NSClassFromString(@"SBJsonWriter"); SEL _SBJsonWriterSelector = NSSelectorFromString(@"dataWithObject:"); id _NXJsonSerializerClass = NSClassFromString(@"NXJsonSerializer"); SEL _NXJsonSerializerSelector = NSSelectorFromString(@"serialize:"); id _NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization"); SEL _NSJSONSerializationSelector = NSSelectorFromString(@"dataWithJSONObject:options:error:"); #ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_ if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) { goto _af_nsjson_encode; } #endif if (_JSONKitSelector && [object respondsToSelector:_JSONKitSelector]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[object methodSignatureForSelector:_JSONKitSelector]]; invocation.target = object; invocation.selector = _JSONKitSelector; NSUInteger serializeOptionFlags = 0; [invocation setArgument:&serializeOptionFlags atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation if (error != NULL) { [invocation setArgument:error atIndex:3]; } [invocation invoke]; [invocation getReturnValue:&data]; } else if (_SBJsonWriterClass && [_SBJsonWriterClass instancesRespondToSelector:_SBJsonWriterSelector]) { id writer = [[_SBJsonWriterClass alloc] init]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[writer methodSignatureForSelector:_SBJsonWriterSelector]]; invocation.target = writer; invocation.selector = _SBJsonWriterSelector; [invocation setArgument:&object atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation [invocation invoke]; [invocation getReturnValue:&data]; [writer release];
  3. When you start a secondary thread, it's common for that

    thread to retain the target object. If you don’t ensure that the thread releases that reference before the main thread releases its last reference to the object, bad things happen.
  4. - (void)setCompletionBlock:(void (^)(void))block { if (!block) { [super setCompletionBlock:nil]; }

    __block id _blockSelf = self; [super setCompletionBlock:^ { block(); [_blockSelf setCompletionBlock:nil]; }]; }