{"id":242,"date":"2017-02-13T05:20:35","date_gmt":"2017-02-13T05:20:35","guid":{"rendered":"http:\/\/inwizards.com\/blog\/?p=242"},"modified":"2022-01-29T13:08:31","modified_gmt":"2022-01-29T13:08:31","slug":"load-big-image-url-without-freezing-app-ios-using-swift-2-0","status":"publish","type":"post","link":"https:\/\/www.inwizards.com\/blog\/load-big-image-url-without-freezing-app-ios-using-swift-2-0\/","title":{"rendered":"How to Load Big Image From URL Without Freezing App In IOS Using Swift 2.0"},"content":{"rendered":"<p><span style=\"color: #000000;\">If you want to load big image from URL so you can use AFNetworking Library into your Project, so with the help of this library you can load big image from url without freezing your app.<\/span><br \/>\n<span style=\"color: #000000;\"> First download AFNetworking Library from GitHub by click on this link<\/span><br \/>\n<span style=\"color: #000000;\"> https:\/\/github.com\/AFNetworking\/AFNetworking<\/span><br \/>\n<span style=\"color: #000000;\"> after download unzip and and add to your project<\/span><br \/>\n<span style=\"color: #000000;\"> 1. now import AFNetworking.h file into your YourProject-Bridging-Header.h file<\/span><br \/>\n<span style=\"color: #000000;\"> and now create object of AFHTTPRequestOperation<\/span><\/p>\n<p><span style=\"color: #000000;\"><strong>Source Code:<\/strong><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\"><span style=\"color: #0000ff;\">let<\/span> UrlString:<span style=\"color: #2b839f;\">NSString<\/span> = <span style=\"color: #a8184b;\">\u201cYour Image URL\u201d<\/span><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\"><span style=\"color: #0000ff;\">let<\/span> ImageURL:<span style=\"color: #2b839f;\">NSURL<\/span> = <span style=\"color: #2b839f;\">NSURL<\/span>(string: UrlString:<span style=\"color: #2b839f;\">NSString<\/span> <span style=\"color: #0000ff;\">as<\/span> <span style=\"color: #2b839f;\">String<\/span>)!<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\"><span style=\"color: #0000ff;\">let<\/span> URLRequest:<span style=\"color: #2b839f;\">NSURLRequest<\/span> = <span style=\"color: #2b839f;\">NSURLRequest<\/span>(URL: ImageURL)<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\"><span style=\"color: #0000ff;\">let<\/span> requestOperation:<span style=\"color: #2b839f;\">AFHTTPRequestOperation<\/span> = <span style=\"color: #2b839f;\">AFHTTPRequestOperation<\/span>(request: URLRequest)<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\">requestOperation.<span style=\"color: #2b839f;\">responseSerializer<\/span> = <span style=\"color: #2b839f;\">AFHTTPResponseSerializer<\/span>()<\/span><\/span><\/span><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-1542270097115731\" data-ad-slot=\"5976953901\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\">requestOperation.<span style=\"color: #2b839f;\">setCompletionBlockWithSuccess<\/span>({ (operation:<span style=\"color: #2b839f;\">AFHTTPRequestOperation<\/span>, data:<span style=\"color: #2b839f;\">AnyObject<\/span>) -&gt; <span style=\"color: #2b839f;\">Void<\/span> <span style=\"color: #0000ff;\">in<\/span><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\"><span style=\"color: #0091ce;\">yourImageView.image<\/span> = <span style=\"color: #2b839f;\">UIImage<\/span>(data: data <span style=\"color: #0000ff;\">as<\/span>! <span style=\"color: #2b839f;\">NSData<\/span>)<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\">}, failure: { (operation:<span style=\"color: #2b839f;\">AFHTTPRequestOperation<\/span>?, error:<span style=\"color: #2b839f;\">NSError<\/span>) -&gt; <span style=\"color: #2b839f;\">Void<\/span> <span style=\"color: #0000ff;\">in<\/span><\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\"><span style=\"color: #0091ce;\">yourImageView.image<\/span> = <span style=\"color: #2b839f;\">UIImage<\/span>(named: <span style=\"color: #a31515;\">\u201cdefault.png\u201d<\/span>)<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\">})<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Menlo-Regular;\"><span style=\"font-size: medium;\">requestOperation.<span style=\"color: #2b839f;\">start<\/span>()<\/span><\/span><\/span><\/p>\n<p class=\"western\"><span style=\"color: #777777;\"><span style=\"font-family: Lato, helvetica, arial, sans-serif;\"><span style=\"font-size: medium;\">)<\/span><\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to load big image from URL so you can use AFNetworking Library into your Project, so with the help of this library you can load big image from url without freezing your app. First download AFNetworking Library<\/p>\n","protected":false},"author":1,"featured_media":243,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"https:\/\/i1.wp.com\/www.inwizards.com\/blog\/wp-content\/uploads\/2017\/02\/awesome_logo.png?fit=1425%2C712&ssl=1","_links":{"self":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/242"}],"collection":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":3,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":1534,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/posts\/242\/revisions\/1534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/media\/243"}],"wp:attachment":[{"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inwizards.com\/blog\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}