matthewcheok / JSONCodable

Hassle-free JSON encoding and decoding in Swift
MIT License
602 stars 66 forks source link

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

Open djdiaz opened 8 years ago

djdiaz commented 8 years ago

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?