Importing SDWebImage into Swift project
So nothing was working for me until I finally realized that you're supposed to use not the main SDWebImage folder, but the SDWebImage folder inside of that into the project. Dragging in the .xcodeproj file, the folder as a whole, or the .framework file didn't work. Importing that sub SDWebImage folder, and then utilizing Libor Zapletal's answer: #import "UIImageView+WebCache.h"
is what finally got this thing working for me.
Lazy Loading : How to integrate SDWebImage with current project?
import this file in your .h
#import "UIImageView+WebCache.h"
and use following method,
[UIImageViewName setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"Placeholder.jpg"]];
How to install SDWebImage
When you add the SDWebImage
folder in your project then select following option. To add copy of your folder to the destination project and Create groups.
and then you have to write just like
#import "UIImageView+WebCache.h"
And make sure that you are adding to all the targets that you want to use that library.
Documentation at Github :
Add the SDWebImage project to your project
- Download and unzip the last version of the framework from the download page
- Right-click on the project navigator and select "Add Files to "Your Project":
- In the dialog, select SDWebImage.framework:
- Check the "Copy items into destination group's folder (if needed)" checkbox
Or you can use cocoa pods
as other answer suggested.
EDIT : EXAMPLE :
[self.imageView sd_setImageWithURL:[NSURL URLWithString:"yoururl.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
SDWebImage crash in swift
The SDWebImageModule is an actively developed open source component. It is much better in this case to raise a bug on GitHub. The developers have already made a few releases that fix Xcode6 and Swift issues.
Comprehending SDWebImage downloader
I've created a class for that, but here's how I use it:
- (void)setImageURL:(NSURL *)imageURL {
_imageURL = imageURL;
self.image = nil;
[self.layer removeAllAnimations];
if (!imageURL) {
self.image = self.placeHolderImage;
return;
}
__weak SDImageView *weakself = self;
self.progressView.hidden = NO;
SDWebImageDownloaderProgressBlock progressBlock =
^(NSInteger receivedSize, NSInteger expectedSize) {
if (expectedSize > 0) {
float progress = receivedSize / (float)expectedSize;
weakself.progressView.progress = MAX(MIN(1, progress), 0);
}
};
SDWebImageCompletionWithFinishedBlock successBlock =
^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (!image) image = self.placeHolderImage;
weakself.imageOperation = nil;
weakself.progressView.hidden = YES;
weakself.progressView.progress = 0.f;
if (cacheType == SDImageCacheTypeNone && !error) {
[UIView transitionWithView:self
duration:1.f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
weakself.image = image;
} completion:nil];
} else {
weakself.image = image;
}
};
SDWebImageManager *manager = [SDWebImageManager sharedManager];
self.imageOperation = [manager downloadImageWithURL:imageURL
options:SDWebImageRetryFailed
progress:progressBlock
completed:successBlock];
}
Related Topics
What's the Difference Between a View and a Viewcontroller
Treat *Some* Warnings as Errors in Swift
Swift Lazy Subscript Ignores Filter
Ycombinator Not Working in Swift
How to Add Constraints Programmatically to My Uilabel
How to Open/View iOS Oslogs Stored on Device
My Data Changes in Uitableviewcell When I Scroll Down and Get Back
When Should I Use Optionals and When Should I Use Non-Optionals with Default Values
Use 'Self' as a Default Parameter
iOS 11 Uirefreshcontrol with Navigationbar Largetitle and Searchcontroller Disappearing
How to Determine If a Variable Passed in Is Reference Type or Value Type
Read a File in a MACos Command Line Tool Project
Scenekit - Animation with Dae File Format
Change Tabview Indicator Swiftui