I am attempting to take in a string literal value like
var s: String = "0.9 1.2 4.8 0.4 3.2 7.9"
And convert it into an array of float3s like this
var f: [float3] = [float3(0.9, 1.2, 4.8), float3(0.4, 3.2, 7.9)]
So far I have written an extension function for string that looks like this
extension String {
func toFloat3Array()->[float3]{
var result = [float3]()
let pointArray: [Float] = self.split(separator: Character(" ")).map { Float($0) ?? 0.0 }
for var i in 0..<pointArray.count - 2 {
result.append(float3(pointArray[i++], pointArray[i++], pointArray[i++]))
}
return result
}
}
*Note: I have created an operator overload for i (++) that returns the value then increases it like you would see in java.
This works just fine, but I am hoping that there is a better way to map the values from the string array into the float3 array :) Thank you!