Project Euler #10 in Swift - Summation of primes
Since we know that primes can be represented by 6x+1 or 6x-1 except for 2,3, we could skip them as follows:

//Handle explicitly for n&lt;5 i.e for n = 0,1,2,3,4 and proceed otherwise.
if n&lt;3 { // n=0,1,2
    return 0
}
if n&lt;5 {// n = 3,4
    return (n==3)?2:5
}

var x = 5
while x &lt;= maxPrime {
    if composite[x] == false {
        for y in stride(from: x * x, through: n - 1, by: x) {
            composite[y] = true
        }
    }
    x+=2 
    if x&lt;n &amp;&amp; composite[x] == false {
        for y in stride(from: x * x, through: n - 1, by: x) {
            composite[y] = true
        }
    }
    x+=4
}

var result = 5 // 2 + 3
for i in stride(from: 5, through: composite.count - 1, by: 4) {
    if composite[i] == false {
        result += i
    }
    i+=2
    if i&lt;n &amp;&amp; composite[i] == false {
        result += i
    }
}


Results: With your code it took me 33ms with mine its down to 23ms.