[英]KeyedDecodingContainer not being called which is in a different package
下面的代碼在 swift package 管理器中,它處理 JSON 解碼器。
//MyJSONPackage
extension KeyedDecodingContainer {
func func decode(_ type: Bool.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Bool
{
/// This is not being called from Main Project.
return try decodeIfPresent(type, forKet: key) ?? .init()
}
}
期望調用它的代碼是一個不同的項目(名為“MainProject”),它使用上面的 package 管理器。
該項目有沒有辦法確保它調用KeyedDecodingContainer.decode
的MyJSONPackage
而不是主項目? 或者如何為特定代碼塊執行MainProject
使用KeyedDecodingContainer.decode
中可用的MyJSONPackage
發現缺少public
關鍵字。
如果 public 缺失,它不會拋出任何錯誤,它會在現有項目中提供默認實現。
如果缺少public
關鍵字並且調用 package 管理器的項目提供默認實現,則其他擴展也可能發生這種情況。
//MyJSONPackage
extension KeyedDecodingContainer {
// public accessor was MISSING.
public func decode(_ type: Bool.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Bool
{
/// This is not being called from Main Project.
return try decodeIfPresent(type, forKet: key) ?? .init()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.