¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Swift Extension on Array - not working ... hmmm


 

class LineUp {

? ? var lineup = ["Bob", "Tony", "Iris", "Jane", "Nan", "Dave", "George", "Ringo", "Shannon" ]

?? ?

? ? subscript(n: Int) -> String {

? ? ? ? var index = 0

? ? ? ? let indexMax = lineup.count

? ? ? ? let indexWrapped = n % indexMax

? ? ? ? //indexWrapped <= 0 ?? index = indexMax : index = indexWrapped - 1

? ? ? ? if ( indexWrapped <= 0 ) { index = indexMax - 1 } else { index = indexWrapped - 1 }

? ? ? ? return lineup[index]

? ? }

}

?

let list = LineUp()

?

print("\(list[1]) batter")

?

list.lineup.append("Paul")

print("\(list[17]) battting last")

print("\(list[18]) battting last")

print("\(list[19]) battting last")

print("\(list[20]) battting last")

print("\(list[21]) battting last")

?

Join [email protected] to automatically receive all group messages.