Swift 调用中的额外参数

标签 swift compiler-errors

我在调用 Swift 项目中的特定方法时遇到问题。这是 ObjC 方法签名:

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;

我无法让它工作,因为 XCode 不断告诉我“调用中存在额外参数‘placeholderImage’”

self.lastLookImageView.setImageWithURL(url,
    placeholderImage: nil,
    options: SDWebImageRefreshCached,
    completed: {
       (image, error, cacheType) -> Void in
       image = image.blurredImageWithRadius(30, iterations: 2, tintColor: UIColor.clearColor())
    }
)

当我 Cmd+Click 时,XCode 甚至无法识别该方法:“找不到符号”。

我怀疑它与该 block 有关,因为我可以调用同一类的其他方法,这几乎是相同的,但没有完成 block 。工作示例:

self.lastLookImageView.setImageWithURL(NSURL(string: self.lastLook!.image), placeholderImage: nil, options: SDWebImageRefreshCached) 

就上下文而言:我在 Obj-C 和 Swift 混合项目中使用了一个名为 SDWebImage ( https://github.com/rs/SDWebImage ) 的组件。该类已导入到我的 Bridging-Header.h

最佳答案

Swift 方法签名应该是:

func setImageWithURL(url: NSURL!, forState state: UIControlState,
            placeholderImage placeholder: UIImage! options: SDWebImageOptions)

所以你需要这样调用它:

self.lastLookImageView.setImageWithURL(url, forState: .Normal, 
            placeholderImage: nil, options: SDWebImageRefreshCached)

此方法没有完成处理程序,因此请将其保留。

关于Swift 调用中的额外参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28437595/

相关文章:

swift - libswiftFoundation.dylib 和 libswiftcore.dylib 是做什么的?

java - 变量可能尚未初始化(边缘加权图)

与 C# 表达式一起使用时,ASP.NET 表达式 <%= ...%> 给出错误 CS 1518

arrays - 如何谓词数组字典来查找匹配值

ios - Swift - 使用bindToPort调用时的参数标签不正确

c++ - 链接 : fatal error LNK1104: cannot open file '..\json_spirit\Debug\json_spirit_lib.lib'

go - 在 Go 中返回 nil 或自定义错误

java - 对于Set类型,未定义()方法

ios - 如何使用 stat 实用程序而不是 subpathsOfDirectoryAtPath 来计算目录大小

ios - 解码奇怪的 AutoLayout 错误消息