Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Video Tutorial: What’s New in Swift 2 Part 5: Protocol Extensions

Learn about protocol extensions, a new feature in Swift 2 that will make you rethink how you design your code.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3609-what-s-new-in-swift-2/lessons/6

Hi Brian,

First, I really enjoy this tutorial and want to thank you.
I did the challenge of this part using this function :

func largest() -> Self.Generator.Element{
var largest: Self.Generator.Element? = nil
for item in self {
if largest < item{
largest = item
print(“The largests is now (largest)”)
}
}
return largest!
}

But you did it in a different way and I’d like to know the best practices in that case :

func largest() -> Generator.Element {
var index = startIndex
var largest = self[index]
while index != endIndex {
if largest < self[index] {
largest = self[index]
}
index = index.successor()
}
return largest
}

Thanks in advance and kind regards

Shkelzen