Utilizzo dei blocchi in Restkit (come ASIHttpRequest Blocchi)
Domanda
Sono stato con il supporto blocco estesamente in ASIHttpRequest, e ho trovato ad essere un modo estremamente elegante di codifica richieste asincrone, molto più che avere la chiamata delegato di nuovo una funzione separata ??p>
Ecco il codice di esempio per una rapida consultazione.
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
}];
[request startAsynchronous];
Vorrei iniziare a utilizzare Restkit, ma ho bisogno di essere in grado di utilizzare Restkit con blocchi pure.
ho visto l'involucro qui Restkit Block Wrapper , ma vorrei verificare se quel involucro avrebbe funzionato bene in produzione, e se qualcuno lo hanno utilizzato ampiamente prima
Soluzione
I have not used the RestKit Block wrapper yet, but I will be shortly. I'm actually removing ASIHTTPRequest from my App and replacing with RestKit. Not because it's bad, ASIHTTP* is quite stable - but it isn't evolving. While many other libraries, like RestKit, wrap NSURLConnection and so reap the benefits of Apples continuing enhancements to it, ASIHTTP* uses CFNetwork. Apple isn't investing a lot of effort in improving preexisting Core Foundation classes (like CFNetwork). Also, since ASIHTTP* depends on CF, it's going to be a royal pain to migrate to ARC when it's available; I wan't the benefits of ARC as soon as possible.
Altri suggerimenti
Blocks support for all the basic delegate tasks on RKRequest and RKObjectLoader will be coming in 0.9.4
Yesterday, Blake released verson 0.9.3 which features the usage of blocks for the Object Mapper (other methods were already ready for blocks). You should take look at the new features.
For a quick code sample to use RestKit with blocks, I derived this snippet from http://kalapun.com/blog/2012/05/17/how-i-restkit/
[[RKClient sharedClient] get:@"/fooBar" usingBlock:^(RKRequest *request) {
request.onDidLoadResponse = ^(RKResponse *response) {
NSLog(@"Retrieved XML: %@", [response bodyAsString]);
};
}];