I am trying to add an extension, that adds two functions to an array of FloatingPoint types. I added to and extension to get a myDesibe var:
extension FloatingPoint {
public var myDescribe:String {
return String(format:"%.3f",self as! CVarArg)
}
}
This works fine (or seems to)
On the collection, I want to add two methods/vars. One method returns a string with command delimited values:
public extension Array where Element: FloatingPoint {
var myDescribe:String {
var rvalue = ""
for (index,entry) in self.enumerated() {
var format = ",%@"
if (index == 0) {
format = "%@"
}
rvalue += String(format: format, entry.myDescribe)
}
return rvalue
}
}
That seems to be working fine. The other I wan to pass the command delimited string in, and get an array of the type of elements of the Array. This does not work:
public extension Array where Element: FloatingPoint {
var myDescribe:String {
func fromDescription(desribe:String) -> [Element] {
var rvalue = [Element]()
for entry in desribe.components(separatedBy: ",") {
let trimmed = entry.trimmingCharacters(in: .whitespaces)
let temp = FloatLiteralType(trimmed) ?? FloatLiteralType.zero
// Now, how to convert this so I can append this in the array? This is the issue!!
rvalue.append(temp) // << THIS FAILS, as it wants an Int which I don't `understand`
}
return rvalue
}
}
All help is appreciated
Charles