When a request is made it is launched with [NSThread detachNewThreadSelector:] which in turn creates a new thread. This is not really efficient, as getting something like a profile picture of all your friends can quickly turn into a big mess.
I was thinking of changing the NSThread calls to use Grand Central Dispatch dispatch_async(). It is quite simple and means that all subsequent calls are queued nicely and no unnecessary threads are created. This however only works on OS X 10.6+. Before making a pull request I thought I'll ask what are your thoughts about backwards compatibility.
If you do think that using blocks is a good idea, I would like to extend the project to include calls that use a supplied block instead of a callback. It makes the code much cleaner and easier to read. For example for the simple sendRequest call an equivalent would be created:
Using this syntax the code for handling request is at the same place where the call is made, rather than putting everything in the - (void) tokenResult: (NSDictionary*) result callback. It would also make the API a bit cleaner, since there is no need of having the NSDictionary as the result - all variables inside it are available in the block anyway.
Let me know what you think as I would love to contribute to this project a bit more.
When a request is made it is launched with
[NSThread detachNewThreadSelector:]
which in turn creates a new thread. This is not really efficient, as getting something like a profile picture of all your friends can quickly turn into a big mess.I was thinking of changing the NSThread calls to use Grand Central Dispatch
dispatch_async()
. It is quite simple and means that all subsequent calls are queued nicely and no unnecessary threads are created. This however only works on OS X 10.6+. Before making a pull request I thought I'll ask what are your thoughts about backwards compatibility.If you do think that using blocks is a good idea, I would like to extend the project to include calls that use a supplied block instead of a callback. It makes the code much cleaner and easier to read. For example for the simple sendRequest call an equivalent would be created:
- (void) sendRequest:(NSString*) request setCompletionBlock:(void (^)(NSString *result)) block
So rewriting part of the sample application using the new call would look like:
Using this syntax the code for handling request is at the same place where the call is made, rather than putting everything in the
- (void) tokenResult: (NSDictionary*) result
callback. It would also make the API a bit cleaner, since there is no need of having theNSDictionary
as the result - all variables inside it are available in the block anyway.Let me know what you think as I would love to contribute to this project a bit more.