How to return a changed array from a function?
Here is a short code snippet to make it clearer:
var tasks = ["Mow the lawn", "Call Mom"] var completedTasks = ["Bake a cake"] func arrayAtIndex(index: Int) -> String[] { if index == 0 { return tasks } else { return completedTasks } } arrayAtIndex(0).removeAtIndex(0)
The following snippet works, but I have to return Array , not NSMutableArray
var tasks: NSMutableArray = ["Mow the lawn", "Call Mom"] var completedTasks: NSMutableArray = ["Bake a cake"] func arrayAtIndex(index: Int) -> NSMutableArray { if index == 0 { return tasks } else { return completedTasks } } arrayAtIndex(0).removeObjectAtIndex(0) tasks
Thanks!
swift
Damien
source share