At present to instantiate a property that is wrapped with the @Attribute property wrapper whose wrapped value conforms to one of the many ExpressibleBy(value type)Literal such as ExpressibleByStringLiteral:
struct TwoStrings: Equatable, Codable {
@Element var string1: String
@Attribute var string2: String
}
Currently in order to instantiate this type, one must do the following:
let twoStrings = TwoStrings(string1: Element.init("Hello"), string2: "Goodbye")
This is because the @Element property wrapper doesn't conform to the ExpressibleByStringLiteral, unlike the @Attribute property wrapper. My suggestion is to the conditional conformance to the ExpressibleByStringLiteral protocol whenever the Value type parameter also conforms to the ExpressibleByStringLiteral protocol. (This suggestion also applies for the other protocols that are of the format ExpressibleBy(value type)Literal protocols such as ExpressibleByIntegerLiteral and ExpressibleByBooleanLiteral). The way that this would be done would be virtually identical to the way this is implemented in the @Attribute property wrapper. (As such, one could argue that this should be implemented with the definition of a protocol that satisfies its own requirements. This protocol could then be inherited by the @Attribute and @Element property wrappers in order to avoid repetitive code).
Regardless of the exact implementation, the adoption of this suggestion would permit the instantiation of the example type as follows (note the similarities between the two properties, despite their differing implementation on the XML side):
let twoStrings = TwoStrings(string1: "Hello", string2: "Goodbye")
At present to instantiate a property that is wrapped with the
@Attributeproperty wrapper whose wrapped value conforms to one of the manyExpressibleBy(value type)Literalsuch asExpressibleByStringLiteral:Currently in order to instantiate this type, one must do the following:
This is because the
@Elementproperty wrapper doesn't conform to theExpressibleByStringLiteral, unlike the@Attributeproperty wrapper. My suggestion is to the conditional conformance to theExpressibleByStringLiteralprotocol whenever theValuetype parameter also conforms to theExpressibleByStringLiteralprotocol. (This suggestion also applies for the other protocols that are of the formatExpressibleBy(value type)Literalprotocols such asExpressibleByIntegerLiteralandExpressibleByBooleanLiteral). The way that this would be done would be virtually identical to the way this is implemented in the@Attributeproperty wrapper. (As such, one could argue that this should be implemented with the definition of a protocol that satisfies its own requirements. This protocol could then be inherited by the@Attributeand@Elementproperty wrappers in order to avoid repetitive code).Regardless of the exact implementation, the adoption of this suggestion would permit the instantiation of the example type as follows (note the similarities between the two properties, despite their differing implementation on the XML side):