I have used SDWebImage with Objective C and it worked great for me but now I am learning Swift and trying to integrate the latest version of the API but I am stucking at every step as API is in Objective C and there are no steps mentioned to use the API with Swift. I read the documents and created the bridge header file and included the required file like below:
#ifndef MyProject_Bridging_Header_h
#define MyProject_Bridging_Header_h
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
#endif
I have added the frameworks as well and dragged the SDWebImage project within my app as explained here
I am really struggling in this. Please help! For reference I have added an image showing the error!
The best option will be to drag and drop SDWebImage folder to project. Make sure 'copy items if needed' is ticked on.
Make a Obj C Bridging:File -> New -> Source -> Header File -> Name as AppName-Bridging-Header.
Add the following:
Reference: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Note: Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting under has a path to the bridging header file. - its like testSD/testSD-Bridging-Header.h or testSD-Bridging-Header.h (Open the Project folder and find the header file path)
Now try with this code:
Suppose if you are using a UICollectionView to populate Cache imaging, try with this code.
swift 3.0 code
Here is a code example that should work :
and in your bridging header file :
So your bridging header file should work, but sometimes I had trouble with the bridging header and in theses cases I just delete it, and add it again and everything works fine after.