bizz84 / MVCarouselCollectionView

UICollectionView-based image carousel written in Swift
MIT License
205 stars 34 forks source link

Synchronous or asynchronous #3

Closed kiwo12345 closed 9 years ago

kiwo12345 commented 9 years ago

Thanks for sharing this. But how do I switch between synchronous or asynchronous remote/local ?

Thanks in advance

bizz84 commented 9 years ago

You can configure MVCarouselCollectionView to use an image loader of your choice (see MVCarouselCollectionView.commonImageLoader). A couple of different image loaders are already provided. Example:

var imageViewLoadCached : ((imageView: UIImageView, imagePath : String, completion: (newImage: Bool) -> ()) -> ()) = {
    (imageView: UIImageView, imagePath : String, completion: (newImage: Bool) -> ()) in

    imageView.image = UIImage(named:imagePath)
    completion(newImage: imageView.image != nil)
}

var imageViewLoadFromPath: ((imageView: UIImageView, imagePath : String, completion: (newImage: Bool) -> ()) -> ()) = {
    (imageView: UIImageView, imagePath : String, completion: (newImage: Bool) -> ()) in

    var url = NSURL(string: imagePath)
    imageView.sd_setImageWithURL(url, completed: {
        (image : UIImage?, error: NSError?, cacheType: SDImageCacheType, imageURL: NSURL?) in

        completion(newImage: image != nil)
    })
}