Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Menu/Swift/menu.swift
Normal file
36
Task/Menu/Swift/menu.swift
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
func getMenuInput(selections: [String]) -> String {
|
||||
guard !selections.isEmpty else {
|
||||
return ""
|
||||
}
|
||||
|
||||
func printMenu() {
|
||||
for (i, str) in selections.enumerated() {
|
||||
print("\(i + 1)) \(str)")
|
||||
}
|
||||
|
||||
print("Selection: ", terminator: "")
|
||||
}
|
||||
|
||||
while true {
|
||||
printMenu()
|
||||
|
||||
guard let input = readLine(strippingNewline: true), !input.isEmpty else {
|
||||
return ""
|
||||
}
|
||||
|
||||
guard let n = Int(input), n > 0, n <= selections.count else {
|
||||
continue
|
||||
}
|
||||
|
||||
return selections[n - 1]
|
||||
}
|
||||
}
|
||||
|
||||
let selected = getMenuInput(selections: [
|
||||
"fee fie",
|
||||
"huff and puff",
|
||||
"mirror mirror",
|
||||
"tick tock"
|
||||
])
|
||||
|
||||
print("You chose: \(selected)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue