virat
virat

Reputation: 117

How to import objective c header file in swift project

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?

Upvotes: 6

Views: 18993

Answers (2)

Alessandro Ornano
Alessandro Ornano

Reputation: 35372

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

                            }
                    })

Upvotes: 8

Fujia
Fujia

Reputation: 1242

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.

Upvotes: 8

Related Questions