I have a problem with generation of an array of substrings from a string in the following code
var primers=[String]()
var lengthOfPrimer = 20
var lentghOfText = str1.characters.count
var rest = lentghOfText - lengthOfPrimer
for var i = 0; i <= str1.characters.count; ++i
{
var temp = rest - i
var substring1 = str1.substringWithRange(Range<String.Index>(start: advance(str1.startIndex, i), end: advance(str1.endIndex, -temp)))
primers.append(substring1)
}
In playground I have the following error at the line with the substring1 code – Execution was interrupted: reason: EXC_BAD_INSTRUCTION (code=EXC 1386_INVOP, subcode=0x0. In spite of error sign, I can see in playground the generated set of substrings in loop, but when I tried to use this code in program this code also did not work, What is wrong? What should I do?