Skip to content

Commit dd33b13

Browse files
committed
infer rootKey and fixed lint errors
1 parent fc304c5 commit dd33b13

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/XMLCoder/Encoder/XMLEncoder.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ open class XMLEncoder {
324324
/// floating-point value is encountered during encoding, and the encoding
325325
/// strategy is `.throw`.
326326
/// - throws: An error if any value throws an error during encoding.
327-
open func encode<T: Encodable>(_ value: T, withRootKey rootKey: String, rootAttributes: [String : String], header: XMLHeader? = nil) throws -> Data {
327+
open func encode<T: Encodable>(_ value: T,
328+
withRootKey rootKey: String? = nil,
329+
rootAttributes: [String: String],
330+
header: XMLHeader? = nil) throws -> Data {
328331
let encoder = XMLEncoderImplementation(
329332
options: options,
330333
nodeEncodings: []
@@ -335,6 +338,8 @@ open class XMLEncoder {
335338
let attributes = rootAttributes.map(Attribute.init)
336339

337340
let elementOrNone: XMLCoderElement?
341+
342+
let rootKey = rootKey ?? "\(T.self)"
338343

339344
if let keyedBox = topLevel as? KeyedBox {
340345
elementOrNone = XMLCoderElement(key: rootKey, box: keyedBox, attributes: attributes)

0 commit comments

Comments
 (0)