That is my partially commented code for finding primes, I used to collect them in an NSMutableArray but doing it in C halved the time. My problem is that I need to create an NSArray to play with once it has finished calculations but it keeps throwing errors as I detailed in the last few lines.
help appreciated 
And if you like it would be really nice if you looked at https://forums.macrumors.com/threads/1216402/

Richard
Code:
- (IBAction)customStart:(id)sender {
NSArray *result = [self runPrimesFromStart:8 toFinish:1000000];
}
- (NSArray *)runPrimesFromStart:(unsigned long long)startValue toFinish:(unsigned long long)endValue
{
NSLog(@"start");
//NSMutableArray *primeNumbers = [NSMutableArray array];
//if startValue is even then use the next odd instead
unsigned long long start = startValue%2 == 0 ? ++startValue : startValue;
//if endValue is even then make the if look for values below, if odd include it, note the n<end below
unsigned long long end = endValue%2 == 0 ? endValue : ++endValue ;
//make array half the range since it will not all be needed
unsigned long long primeNumbers[((2+end-start)/2)];
unsigned long long primeCount = 0;
for (unsigned long long n = startValue; n<end; (n++, n++)) {
BOOL y = YES;
for (unsigned long long x = 3; (x <= sqrtl(n)) && y; x++) {
//NSLog(@"in repeat");
if (n%x == 0) {
y = NO;
//NSLog(@"%llu is not prime", n);
}
}
if (y == YES) {
++primeCount;
primeNumbers[primeCount] = n;
//[primeNumbers addObject:[NSNumber numberWithUnsignedLongLong: n]];
//NSLog(@"%llu is prime", n);
}
//NSLog(@"finished checking");
}
//make primeCount the first item of the array
primeNumbers[0] = primeCount;
//logging item 0, 1 and 2 is successful here
NSArray *result = [NSArray arrayWithObjects:primeNumbers count:primeCount];//throws "Program received signal 'EXC_BAD_ACCESS' "
return result;
}
And if you like it would be really nice if you looked at https://forums.macrumors.com/threads/1216402/
Richard