Creating a swift command line to-do list app

let Numbers = [7,8,9,10,13,14]
let streets = ["Albemarle", "Brandywine", "Chesapeake"]
var toDolist: Array<String> = Array()=> []
let task1: String = “Brush Teeth”
toDolist.append(task1)
=> ["Brush Teeth"]
toDolist.append(contentsOf:[task1, task2, task3])
print(toDolist)
=> ["Brush Teeth", "Comb Hair", "Call Holly"]
func newTask(task: String) -> Array<String>  {toDolist.append(task)return toDolist}print(newTask(task: "Make Breakfast"))
=> ["Brush Teeth", "Comb Hair", "Call Holly", "Make Breakfast"]
newTask(task: "Eat Breakfast")
newTask(task: "Cook Dinner")
print(toDolist)
=> ["Eat Breakfast", "Cook Dinner"]
var toDolist: Array<String> = Array();func newTask(task: String) -> Array<String>  {toDolist.append(task)return toDolist}newTask(task: "Eat Breakfast")newTask(task: "Cook Dinner")
print(toDolist)
let foundTask = toDolist.firstIndex(of: "Cook Dinner")
=> Optional(1)
toDolist.remove(at: foundTask!) 
func taskMachine(task: String) -> Array<String>{var chosenTask: Int = toDoList.firstIndex(of: task) ?? -1toDoList.remove(at: chosenTask)return toDoList}print(taskMachine(task: "Cook Dinner"))
var chosenTask: Int = toDoList.firstIndex(of: task) ?? -1
if (chosenTask != -1) {toDoList.remove(at: chosenTask)return toDoList}
else{
toDoList.append(task)
return toDoList
}
print(toDoList) => []taskMachine(task: "Refry the beans")taskMachine(task: "Take a cold shower")taskMachine(task: "Comb my hair")=> ["Refry the beans", "Take a cold shower", "Comb my hair"]
taskMachine(task: “Refry the beans”)
=> ["Take a cold shower", "Comb my hair"]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store