JSONCodable icon indicating copy to clipboard operation
JSONCodable copied to clipboard

JSONEncoder.encode(_:,key:) fails to compile with value argument cast to JSONEncodable

Open djdiaz opened this issue 9 years ago • 0 comments

This fails to compile:

let val: JSONEncodable = SomeTypeThatImplementsJSONEncodable()
public func toJSON() throws -> AnyObject {
    return try JSONEncoder.create { encoder in
        try encoder.encode(val, key: "SomeKey")
    }
}

The error given is "Cannot invoke 'encode' with an argument list of type '(JSONEncodable, key: String)'." This seems to be because the following method on JSONEncoder is marked private:

private func encode(value: JSONEncodable, key: String) throws

Is there some reason this shouldn't be marked public?

djdiaz avatar Aug 28 '16 12:08 djdiaz