我正在努力将 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/