Answer the question
In order to leave comments, you need to log in
Why is String not being converted to Int?
Greetings!
There is a task: to create a class that will store huge integers (up to 40 elements) using an array.
In the class, I have 2 properties: an array and a variable of type Boolean, which shows a negative number or not.
var GeneralMassive = [Int](repeating: 0, count: 40) //Создаем массив 40 целых чисел, забитый нулями.
var isMinus : Bool = false // Опциональная переменная
public init (integer: String) {
var inStr : String
var lastStr : String
var lastInt : Int
inStr = integer //Приравниваем входящую строку к переменной inStr
lastStr = String(inStr.removeLast()) //Получаем последний символ этой строки (тип Character) и конвертируем его в String
lastInt = Int!(lastStr) //Пытаемся конвертировать String в Int
//Добавление в массив
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question