ios – Redundant Conformance – Stack Overflow


I have the following extension and protocol conformance in my project:

//Extension
extension RawRepresentable where Self: Codable {
    // return value as a string
    public var rawValue: String {
        if let json = try? JSONEncoder().encode(self), 
           let string = String(data: json, encoding: .utf8) {
            return string
        } else {
            return "{}"
        }
    }
    
    // parse value from a string
    public init?(rawValue: String) {
 
        if let value = try? JSONDecoder().decode(Self.self, from: Data(rawValue.utf8)) {
            self = value
        } else {
            return nil
        }
    }
}
//Protocol
extension Optional: RawRepresentable where Wrapped: Codable {}

Building the app target(iOS) succeeds but building the test target(unit tests) fails with the error
Redundant conformance of 'Optional<Wrapped>' to protocol 'RawRepresentable'

When I removed the protocol conformance, the app target fails due to an error with this statement:
@AppStorage(StorageKeys.bag.rawValue) var bag: Bag? = nil

The error is as follows:

Candidate requires that the types 'Bag?' and 'Bool' be equivalent (requirement specified as 'Value' == 'Bool')
Candidate requires that the types 'Bag?' and ‘In’t be equivalent (requirement specified as 'Value' == ‘Int’)
Candidate requires that the types 'Bag?' and ‘Double’ be equivalent (requirement specified as 'Value' == ‘Double’)
Candidate requires that the types 'Bag?' and ‘String’ be equivalent (requirement specified as 'Value' == ‘String’)
Candidate requires that the types 'Bag?' and ‘URL’ be equivalent (requirement specified as 'Value' == ‘URL’)
Candidate requires that the types 'Bag?' and ‘Data’ be equivalent (requirement specified as 'Value' == ‘Data’)

I have used the Xcode’s find symbol in workspace functionality but I can’t find that protocol conformance elsewhere. How do I resolve this issue without updating bag definition?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img