Watching the "Building Better Apps with Value Types in Swift" WWDC video, and got to the part where he talks about the Sieve of Eratosthenes routine. Thought I'd plug it into a playground:
func primes(n: Int) -> [Int] {
var numbers = [Int](2..<n)
for i in 0..<n-2 {
guard let prime = numbers[i] where prime > 0 else {continue}
for multiple in stride(from: 2 * prime*2,to: n-2, by: prime) {
numbers[multiple] = 0
}
}
return numbers.filter { $0 > 0 }
}But on the line with the guard statement, I'm getting an error:
initializer for conditional binding must have Optional type, not 'Int'Is this not allowed? I know an 'if let' has to have an optional, but I thought a 'guard' didn't need one?
Thanks.