无法将类型'(_,_) - >()'的值转换为预期参数类型UserProfile.Completion'Swift 3
问题描述:
我正在使用FacebookCore(我认为问题存在),并且出现错误“当我尝试编译时,无法将类型(_, _) ->()
的值转换为预期参数类型UserProfile.Completion
”。无法将类型'(_,_) - >()'的值转换为预期参数类型UserProfile.Completion'Swift 3
错误出现在第一行,并且代码
UserProfile.loadCurrent() { (userProfile, error) in
guard let userProfile = userProfile else {
completion(profile: nil, error: Error(domain: "FacebookLoginManager", code: 333, userInfo: ["description" : "Error al obtener el perfil del usuario"]))
return
}
completion(profile: userProfile, error: error)
}
UserProfile.Completion
代码
public typealias Completion = (FetchResult) -> Void
而且FetchResult
代码
extension UserProfile.FetchResult {
internal init(sdkProfile: FBSDKProfile?, error: Error?) {
if let error = error {
self = .failed(error)
} else if let sdkProfile = sdkProfile {
let profile = UserProfile(sdkProfile: sdkProfile)
self = .success(profile)
} else {
let error = NSError(domain: "", code: 42, userInfo: nil)
self = .failed(error)
}
}
}
答
通过查看FacebookCore文档,它看起来像是的完工关闭10是FetchResult
类型,是一个枚举:
(FetchResult) -> Void
,而不是:
(UserProfile?,Error?) -> Void
你应该改变它,像这样:
UserProfile.loadCurrent() { (fetchResult) in
UserProfile.loadCurrent { (fetchResult) in
switch fetchResult {
case .success(let userProfile):
completion(profile: userProfile, error: nil)
case .failed(let error):
completion(profile: nil, error: Error(domain: "FacebookLoginManager", code: 333, userInfo: ["description" : "Error al obtener el perfil del usuario"]))
}
}
}
FetchRsult是初始化用户配置。 FetchResult.swift,在pod FacebookCore中。 'public enum FetchResult {case}成功(UserProfile) 大小写失败(错误)}' –
@CarlosGutiérrez检查了FacebookCore文档后,这应该是一个更准确的答案! – Thomas