-->

SDWebImage/UIImageView+WebCache.h file not found

2019-02-02 17:30发布

问题:

I'm trying to use SDWebImage in my iPhone app. I followed the step by step tutorial to install SDWebImage into my Xcode project.

When I try to build my app i'm getting the following error:

Lexical or Preprocessor Issue
'SDWebImage/UIImageView+WebCache.h' file not found 

Can somebody help me solve this issue?

回答1:

A much cleaner "install" of SDWebImage would be as follow:

  1. Drag SDWebImage folder from Finder into your Xcode's project
  2. On any .m file where you wish to use it add: #import "UIImageView+WebCache.h"

    (and any other SD component needed)

    instead of what you probably did: #import <SDWebImage/UIImageView+WebCache.h>

this does not require any project header manipulation and will work as is.



回答2:

It may happen that:

Unzipping this framework, the directory name may be the following: "SDWebImage-3.3.framework"

If you import the project this way, causes the error "framework SDWebImage not found" when compiling.

You need renaming, deleting "-3.3". Would be: "SDWebImage.framework"

Forcing the renamed from Xcode, causes a bug that close unexpectedly the IDE. Renames from Finder and add framework again.

I hope it's useful ...



回答3:

I would not wish my worst enemy the frustration I had to go through to fix this problem because none of these solutions helped in my particular case. If your project compiled earlier, you came back to it and this error popped out of nowhere, chances are you've moved it to some new directory - so go to Build Settings > Search Paths > under Framework Search Paths delete the outdated path, create a new one and set it to "$(SRCROOT)" (without quotes) and change the default "non-recursive" to "recursive". I hope this spares someone the agony I endured.



回答4:

The @Lizard answer saved my day!

$(SRCROOT)/SDWebImage to Header Search Path

Just to be more specific, you have to add that configuration in your target and not in the project view.



回答5:

Check if you have linked the file correctly and its in your bundle or not.



回答6:

Use

#import "UIImageView+WebCache.h"

instead of

#import <SDWebImage/UIImageView+WebCache.h>

Will solve it.



回答7:

Using #import <SDWebImage/UIImageView+WebCache.h> fixed the issue for me as I was using Cocoapods as frameworks (use_frameworks!).



回答8:

I had .xcodeproj and .xcworkspace files and launched the code using .xcodeproj and got this error, but with .xcworkspace it worked fine



回答9:

I was also getting this problem. Solution for me was to add SDWebImage.framework, instead of adding all files in my project. Here is the check list to make sure everything is setup as suggested by auther here.

Download and Add framework

Step 1: Download and unzip the lastest version here: https://github.com/rs/SDWebImage/wiki/Download-Complied-Framework

Step 2: Right-click on the project navigator and select "Add Files to "Your Project": In the dialog, select SDWebImage.framework, and check the "Copy items into destination group's folder (if needed)" checkbox

Add dependencies

In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block: Click the "+" button again and select the "ImageIO.framework"

Add Linker Flag

Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:

Import headers in your source files

#import <SDWebImage/UIImageView+WebCache.h>

It should build now without any problem.