I have a string with the following format:
var cadenaCoordenadas = """
1,1
1,3
4,1
5,1
1,5
1,6
2,5
0,0
"""
What I want is that each line is in the following format (in an array) to manipulate it (with Int data types as I will do operations with the new string): [1,1]
I have the following code:
var arregloEntradas = cadenaCoordenadas.split(separator: "\n")
print("primer Arreglo: ", arregloEntradas)
for i in stride(from: 0, through:arregloEntradas.count - 1, by: 1){
let arregloEntradasFinal = arregloEntradas[i].split(separator: ",")
print(arregloEntradasFinal)
}
and I get the result of this:
as you can see, the array elements are of string type, however I require them to be of Int type:
[1,1]
[1,3]
[4,1]
...
I hope you can help me, thank you in advance.
for i in stride(from: 0, through:arregloEntradas.count - 1, by: 1)is a bad way of sayingfor i in stride(from: 0, to: arregloEntradas.count, by: +1), which is a really complicated way of sayingfor i in 0..<arregloEntradas.count, which is a really error prone way of sayingfor i in arregloEntradas.indices. But you don't even need the index, you need the element, so it could just befor arregloEntradasFinal in arregloEntradas.