Skip to content

Instantly share code, notes, and snippets.

@isoiphone
Created July 1, 2013 20:46
Show Gist options
  • Save isoiphone/5904478 to your computer and use it in GitHub Desktop.
Save isoiphone/5904478 to your computer and use it in GitHub Desktop.
Helpful debugging snippet for AFNetworking
#ifdef DEBUG
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidStartNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSURLRequest* req = [[note object] request];
dbgLog(@"REQUEST: %@ %@", [req HTTPMethod], [req URL]);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidFinishNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
AFHTTPRequestOperation* afop = [note object];
NSURLRequest* req = [afop request];
dbgLog(@"RESPONSE: %@ %@ (%d) >>\n%@\n<<", [req HTTPMethod], [req URL], [[afop response] statusCode], [afop responseString]);
}];
#endif
@isoiphone
Copy link
Author

dbgLog() is just a macro that expands to NSLog() in debug builds (and empty in release builds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment