Open owenzhao opened 3 years ago
Solved. I read the source code of XMLCoder, and in DynamicNodeEncoding.swift
, there is
extension Array: DynamicNodeEncoding where Element: DynamicNodeEncoding {
public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding {
return Element.nodeEncoding(for: key)
}
}
So I make it as a copy for List
extension List: DynamicNodeEncoding where Element: DynamicNodeEncoding {
public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding {
return Element.nodeEncoding(for: key)
}
}
// results
<foo id="606bf34ba0066ab968b69b2b">
<number id="606bf34ba0066ab968b69b2e" />
<number id="606bf34ba0066ab968b69b2f" />
<number id="606bf34ba0066ab968b69b30" />
</foo>
And it worked. So I guess for people who use Realm, you should do this too.
Results:
Expected: The
id
s in number should be attributes instead of elements.If I change
let numbers = List<Bar>()
tovar numbers = [Bar]()
, the issue is gone. So I think there must be something wrong here and I don't know what to do next. As the Realm requests to useList
instead ofArray
here. Any suggestions?