5

I'm trying to use SDWebImage in swift, the file id like to use is called UIImageView+WebCache.h

i added it to my bridging header using

#import "UIImageView+WebCache.h"

Now i am trying to load that file in swift using:

var webCah = UIImageView+WebCache()

and i get an error message reading:

Use of unresolved identifier 'WebCache'

I believe it thinks i am trying to use a uiimageview, when i am just trying to use that objective-c class

How Do i Call that class properly?

inVINCEable
  • 2,167
  • 3
  • 25
  • 49

1 Answers1

4

UIImageView+WebCache is category that extends the functionality UIImageView with SDWebImage specific methods. You need to access the methods defined in it on a UIImageView object.

Example code:

var imageView :UIImageView = UIImageView() // example, this will probably come from elsewhere in your app
imageView.sd_imageURL
// Or

imageView.sd_cancelCurrentImageLoad

Look at the documentation to see what methods are available, or the source https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImageView%2BWebCache.h

Tim
  • 8,932
  • 4
  • 43
  • 64
  • I just stared using swift a few days ago, How would i do that? – inVINCEable Nov 04 '14 at 15:46
  • See my edit. Once you have a UIImageView object, you can access those methods using the dot notation in Swift – Tim Nov 04 '14 at 15:47
  • how would i use something like this func sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; – inVINCEable Nov 04 '14 at 15:53
  • 2
    The same way you call any other method in Swift on an object `objectName.sd_setImageWithURL(url, placeholder:image)` or similar, not sure on the syntax, not at my dev machine at the moment. – Tim Nov 04 '14 at 16:05
  • @Jeff HI Jeff! I am also facing the same issue. Can you please let me know what all steps you followed to get this worked? – Developer Dec 22 '14 at 07:39
  • Not sure what else to describe other than what is already in the answer – Tim Dec 22 '14 at 17:39