如何在我的基于 Swift 的项目中集成最新的 SDWebImage API? [英] How to integrate latest SDWebImage API in my Swift based project?
问题描述
我已经将 SDWebImage 与 Objective C 一起使用,它对我很有用,但现在我正在学习 Swift 并尝试集成最新版本的 API,但我坚持每一步,因为 API 在 Objective C 中并且没有任何步骤提到将 API 与 Swift 一起使用.我阅读了文档并创建了桥头文件并包含了如下所需的文件:
I have used SDWebImage with Objective C and it worked great for me but now I am learning Swift and trying to integrate the latest version of the API but I am stucking at every step as API is in Objective C and there are no steps mentioned to use the API with Swift. I read the documents and created the bridge header file and included the required file like below:
#ifndef MyProject_Bridging_Header_h
#define MyProject_Bridging_Header_h
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
#endif
我也添加了框架并将 SDWebImage 项目拖到我的应用程序中,如这里
I have added the frameworks as well and dragged the SDWebImage project within my app as explained here
我在这方面真的很挣扎.请帮忙!作为参考,我添加了一张显示错误的图片!
I am really struggling in this. Please help! For reference I have added an image showing the error!
推荐答案
这是一个应该可以工作的代码示例:
Here is a code example that should work :
let block: SDWebImageCompletionBlock! = {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType!, imageURL: NSURL!) -> Void in
println(self)
}
let url = NSURL(string: "http://placehold.it/350x150")
self.imageView.sd_setImageWithURL(url, completed: block)
并在您的桥接头文件中:
and in your bridging header file :
#import "UIImageView+WebCache.h"
所以你的桥接头文件应该可以工作,但有时我遇到桥接头文件的问题,在这些情况下我只是删除它,然后再次添加它,之后一切正常.
So your bridging header file should work, but sometimes I had trouble with the bridging header and in theses cases I just delete it, and add it again and everything works fine after.
这篇关于如何在我的基于 Swift 的项目中集成最新的 SDWebImage API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!