¿Hay alguna diferencia entre dataWithContentsOfURL (enhebrado) y dataTaskWithURL?
Estamos usando dataWithContentsOfURL porque es, eh, simple ...
NSData *datRaw = [NSData dataWithContentsOfURL:ur];
Ahora, por supuesto, eso colgará el hilo principal de la interfaz de usuario.
Entonces lo ponemos en otro hilo. Hacemos eso exactamente así,
-(void)performSearch:(NSString *)stuff then:(void(^)(void))after
{
dispatch_queue_t otherThread =dispatch_queue_create(nil,0);
dispatch_queue_t mainThread =dispatch_get_main_queue();
dispatch_async(otherThread,
^{
self.resultsRA = [self ... calls dataWithContentsOfURL ...];
dispatch_async(mainThread, ^{ if (after) after(); });
});
}
(Por cierto, aquí hay una excelente introducción a eso si es necesariohttps://stackoverflow.com/a/7291056/294884)
Bueno, ahora Apple te diceno debe usar dataWithContentsOfURL, dicendeberías en cambio solo usa NSSession. Entonces,dataTaskWithURL:completionHandler:
Mi pregunta, ¿hay alguna diferencia entre hacer nuestro propio hilo (es decir, con dataWithContentsOfURL) versus usar dataTask?
¿Nos equivocamos al usar dataWithContentsOfURL: en un hilo, por alguna razón? Aprecio que sea más conveniente, etc. Quiero decir que hay una diferencia real, cualquier peligro, etc.