I'm making a String struct (called ScalarString
) from scratch that internally is an array of UInt32
Unicode scalar values (see this question for background).
For a normal Swift String
I can do the following:
let myString: String = "hello"
I would like to do
let myScalarString: ScalarString = "hello"
where I overload the assignment operator to convert the "hello" String
automatically to ScalarString
behind the scenes. However, this SO Q&A tells me that is not possible.
I could write a method like
myScalarString.set("hello")
but that isn't as readable as the assignment operator. Is there any alternative?
myScalarString = "hello"