Answer the question
In order to leave comments, you need to log in
How to start a for loop from a given index in Swift 4?
Hello, the question itself is in the title:
if let range = getHtml.range(of:"recipeInstructions") {
let startPos = getHtml.distance(from: getHtml.startIndex, to: range.lowerBound)
let endPos = getHtml.distance(from: getHtml.startIndex, to: range.upperBound)
print(startPos, endPos)
//Как начать с endPos?)
for element in getHtml {
}
}
Answer the question
In order to leave comments, you need to log in
You can use the good old cyclefor in
// Твой массив
let array = [0,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3]
// Позиция, с которой стоит начать прогон по массиву
let endPos = 5
// Так как начало задаем сами,
// то надо быть уверененными,
// что endPos входит в рамки массива
if endPos < array.count {
// старый добрый For in
for i in endPos..<array.count {
// Получаем элемент из массива по индексу
// Это очень быстрая операция, не стоит переживать из-за времени
let item = array[i]
// дальше совершаем какие-то действия с элементом массива
print(item)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question