swift3 - Swift 2.3 到 Swift 3.0 对成员 'joined' 出现模糊引用错误

标签 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: " ")
    }
}

但我收到错误:对 Swift 3.0 代码中的激光返回的 memeber 'joined()' 的引用不明确。

如何解决这个问题?我做了很多研究,但找不到有效的解决方案。

谢谢

最佳答案

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: " ")

关于swift3 - Swift 2.3 到 Swift 3.0 对成员 'joined' 出现模糊引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41271767/

相关文章:

ios - swift 2.3 到 swift 3.0

ios - 在 Xcode Swift 3 中使用约束时水平 slider 消失

ios - swift 3 WKWebView 'URLRequest';您的意思是使用 'as' 进行显式转换吗? ( 漏洞 )

swift - JSQMessageViewController 打开时崩溃

ios - 错误 : Attemped to add a SKNode which already has a parent

swift - 在 Xcode 8 中创建 socket 集合

ios - 无论我尝试什么,UIScrollView 都不会滚动

ios - Swift - 自定义 UIImageView 类

ios - info.plist中的网络身份验证

iOS - 在堆栈 View 中以编程方式添加垂直线