Loading/Downloading image from URL on Swift

前端 未结 30 2568
感动是毒
感动是毒 2020-11-21 05:39

I\'d like to load an image from a URL in my application, so I first tried with Objective-C and it worked, however, with Swift, I\'ve a compilation error:

30条回答
  •  执念已碎
    2020-11-21 05:52

    Swift 2.2 || Xcode 7.3

    I got Amazing results!! with AlamofireImage swift library

    It provides multiple features like:

    • Asynchronously download
    • Auto Purging Image Cache if memory warnings happen for the app
    • Image URL caching
    • Image Caching
    • Avoid Duplicate Downloads

    and very easy to implement for your app

    Step.1 Install pods


    Alamofire 3.3.x

    pod 'Alamofire'

    AlamofireImage 2.4.x

    pod 'AlamofireImage'

    Step.2 import and Use

    import Alamofire
    import AlamofireImage
    
    let downloadURL = NSURL(string: "http://cdn.sstatic.net/Sites/stackoverflow/company/Img/photos/big/6.jpg?v=f4b7c5fee820")!
    imageView.af_setImageWithURL(downloadURL)
    

    that's it!! it will take care everything


    Great thanks to Alamofire guys, for making iDevelopers life easy ;)

提交回复
热议问题