6

enter image description here

I am trying to use SDWebImage in a Swift project. I dragged and dropped the SDWebImage library folder into my Swift project and created a bridging header by name listingApp-Bridging-Header.h

Then I imported the header file into my Swift file; like so imported

    import UIImageView+WebCache.h  

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

    let cell : TableViewCell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as! TableViewCell


    let strTitle : NSString = arrDict[indexPath.row].valueForKey("clip_name") as! NSString

      cell.clipName.text = strTitle as String


    cell.videoImage sd_setImageWithURL=NSURL URLWithString,[NSString stringWithFormat:@"%@%@",K_Server_imageurl,[record valueForKey:@"clip_image_path"]];



        return cell

}

It's giving me an error saying add ; before + How would I import the file above into my Swift project correctly?

9

2 Answers 2

8

You need to quote the header file name when importing it in the bridging header. Like this:

#import "UIImageView+WebCache.h";

This is exactly the same syntax as importing header files in objc.

Sign up to request clarification or add additional context in comments.

9 Comments

imported header file like #import UIImageView+WebCatche.h in the bridging header also
Then you should be able to use the code in swift without importing anything in swift file.
it is giving error in my bringing header file as "UIImageView+WebCatche.h" file not found
You need to check the project header search path. And adding the 'umbrella' header would be better than adding headers individually.
You don't need to import anything in your swift file because you have imported them in the bridging header.
|
8

It's not enough, you must add this bridge header filename also in your Build Settings - Swift Compiler Code Generation like in this picture:

enter image description here

Don't forget also this (required by SDWebImage):

enter image description here

About the next step:

imageDownloader.downloadImageWithURL(
                        NSURL(string: urlString!),
                        options: SDWebImageDownloaderOptions.UseNSURLCache,
                        progress: nil,
                        completed: { (image, data, error, bool) -> Void in
                            if image != nil {
                                self.bannerImageView.image = image

                            }
                    })

9 Comments

it is giving error in my bringing header file as "UIImageView+WebCatche.h" file not found
done with all your suggested steps but now its giving me error in bridging header file as : "UIImageView+WebCatche.h" file not found
Have you drag and drop the full proj?
now it is giving me error in viewController.swift file that : at this line import UIImageView+WebCache.h like this it is giving me error saying add ; before + sign that consecutive statements must be separated by ;
now it is giving me error in viewController.swift file that : at this line import UIImageView+WebCache.h like this it is giving me error saying add ; before + sign that consecutive statements must be separated by ;
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.