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?

Konsy
  • 306
  • 3
  • 22
virat
  • 117
  • 1
  • 1
  • 7

2 Answers2

7

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

                            }
                    })
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
  • it is giving error in my bringing header file as "UIImageView+WebCatche.h" file not found – virat Jul 18 '16 at 06:47
  • done with all your suggested steps but now its giving me error in bridging header file as : "UIImageView+WebCatche.h" file not found – virat Jul 18 '16 at 06:48
  • Have you drag and drop the full proj? – Alessandro Ornano Jul 18 '16 at 06:52
  • 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 ; – virat Jul 18 '16 at 06:52
  • 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 ; – virat Jul 18 '16 at 06:54
  • You must also make a clean of the project, try to remove derivedData, then re-build all – Alessandro Ornano Jul 18 '16 at 06:56
  • not working deleting derived data also please check the image i have added – virat Jul 18 '16 at 07:02
  • ok i have edited my code have a look so how should use sdimage now to set my image view to show images – virat Jul 18 '16 at 07:26
  • No please, stop it. You cannot change your question on the fly whenever you want, please open another question and flag this as answered (choose the answer you want): people have just answer to the main question title, if you change your question content this thread become completely incomprehensible – Alessandro Ornano Jul 18 '16 at 07:31
7

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.

Fujia
  • 1,232
  • 9
  • 14
  • imported header file like #import UIImageView+WebCatche.h in the bridging header also – virat Jul 18 '16 at 06:32
  • Then you should be able to use the code in swift without importing anything in swift file. – Fujia Jul 18 '16 at 06:36
  • it is giving error in my bringing header file as "UIImageView+WebCatche.h" file not found – virat Jul 18 '16 at 06:41
  • You need to check the project header search path. And adding the 'umbrella' header would be better than adding headers individually. – Fujia Jul 18 '16 at 06:50
  • 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 ; – virat Jul 18 '16 at 06:53
  • sorry, i forget to append semi-colon after the import statement. See my updated answer. – Fujia Jul 18 '16 at 06:58
  • 2
    You don't need to import anything in your swift file because you have imported them in the bridging header. – Fujia Jul 18 '16 at 07:04
  • ok i have edited my code have a look so how should use sdimage now to set my image view to show images @Fijia – virat Jul 18 '16 at 07:13
  • thanks your comment : You don't need to import anything in your swift file because you have imported them in the bridging header. – worked for me – virat Jul 18 '16 at 08:05