Learn Concurrency in iOS | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/10376245-networking-with-urlsession/lessons/3

Noticed that the included code for primality test is incorrect. :grin: At the bottom is the (incorrect) code snippet from the tutorial. Here’s an updated code snippet tweaked to correctly calculate:

func isPrime(number: Int) -> Bool {
    if number <= 1 {
      return false
    }
    
    if number <= 3 {
      return true
    }
    
    if number % 2 == 0 {
      return false
    }
    
    var i = 3
    while i * i <= number {
      if number % i == 0 {
        return false
      }
      i = i + 2
    }
    return true

existing code (incorrect)

  func isPrime(number: Int) -> Bool {
    if number <= 1 {
      return false
    }
    
    if number <= 3 {
      return true
    }
    
    var i = 2
    while i * i <= number {
      if number % i == 0 {
        return false
      }
      i = i + 2
    }
    return true
  }