I have readLine() which gives me the character. So, I have this:
223 345 567 and so on. So, when I convert them to Int first thing says these are character so, I researched and found this solution and when I use this:
let size = readLine()
var array = [Int]()
let numbers = readLine()
for number in numbers!
{
if let integer = Int(String(number))
{
array.append(integer)
}
}
print(array)
So, when I am printing the array, I am getting these as [2,2,3,3,4,5,5,6,7] instead of [223,345,567]. Can anyone help?
Here is the extract of new code.
let numbers = readLine()
var array = [Int]()
guard let numberStrings = numbers?.components(separatedBy: " ") else{
fatalError()
}
for number in numberStrings {
if let validNumber = Int(number) {
array.append(validNumber)
}
}
print(array)