Swift 2.3到Swift 3.0会给会员带来不明确的参考错误'加入'

时间:2016-12-21 20:57:12

标签: swift3 xcode8

我正在将swift 2.3转换为swift 3.0;

Swift 2.3代码:

extension ContextDidSaveNotification: CustomDebugStringConvertible {
    public var debugDescription: String {
        var components = [notification.name]
        components.append(managedObjectContext.description)
        for (name, set) in [("inserted", insertedObjects), ("updated", updatedObjects), ("deleted", deletedObjects)] {
            let all = set.map { $0.objectID.description }.joinWithSeparator(", ")
            components.append("\(name): {\(all)}")
        }
        return components.joinWithSeparator(" ")
    }
}

Swift 3.0代码:

extension ContextDidSaveNotification: CustomDebugStringConvertible {
    public var debugDescription: String {
        var components = [notification.name]
        components.append(Notification.Name(rawValue: managedObjectContext.description))
        for (name, set) in [("inserted", insertedObjects), ("updated", updatedObjects), ("deleted", deletedObjects)] {
            let all = set.map { $0.objectID.description }.joined(separator: ", ")
            components.append(Notification.Name(rawValue: "\(name): {\(all)}"))
        }
        return components.joined(separator: " ")
    }
}

但是我收到了错误:对于memeber'加入()' 的模糊引用,以获取Swift 3.0代码中的lase返回值。

如何解决这个问题?我做了很多研究,但无法找到可行的解决方案。

由于

1 个答案:

答案 0 :(得分:5)

joined(separator:)宣布为Array<String>,而不是Array<Notification.Name>

// somewhere in standard library
extension Array where Element == String {

    public func joined(separator: String = default) -> String
}

正如@vadian所指出的那样,Notification.Name不等同于String,所以你需要先转换你的数组。这应该有效:

components
  .map({ $0.rawValue })
  .joined(separator: " ")