I want to get values from one array, and put them into another array using recursion function.And want to notice that I do not want to use loop(like 'for in loop')
var rudics = ["one", "two", "three", "four", "five", "six"]
var array = [""]
func changeArray (var new:[String]) {
array = [new.first!]
if new.count > 0 {
new.removeLast()
changeArray(new)
}
}
changeArray(rudics)
it gives me an error
fatal error: unexpectedly found nil while unwrapping an Optional value
Playground execution failed: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
and so on..
please help me!
array = [new.first!]. You are doing it before checking fornew.countandnewmight be empty at that time.