2016-12-21 33 views
1

我正在將swift swift 2.3轉換爲swift 3.0;Swift 2.3到Swift 3.0獲取模糊引用錯誤給成員'joined'

雨燕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(" ") 
    } 
} 

雨燕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代碼中。

如何解決這個問題?我做了很多研究,但找不到工作解決方案。

感謝

+0

嘗試顯式聲明組件var初始化的類型。 –

+2

'Notification.Name'是Swift 3中的一個結構 - 而不是一個字符串 - 這不是'joined()'所期望的 – vadian

回答

3

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: " ") 
相關問題