+ (NSArray *)allPrimesUpTo:(NSInteger)maxPrime
{
NSMutableArray *allNumbers = [NSMutableArray array];
for (int i = 2; i <= maxPrime; i++) {
[allNumbers addObject:[NSNumber numberWithInt:i]];
}
 
NSMutableArray *primes = [NSMutableArray arrayWithCapacity:maxPrime/2];
while (allNumbers.count > 0) {
NSNumber *firstPrime = [allNumbers objectAtIndex:0];
[primes addObject:firstPrime];
NSMutableArray *nonPrimes = [NSMutableArray array];
for (int i = firstPrime.intValue; i <= maxPrime; i += firstPrime.intValue) {
[nonPrimes addObject:[NSNumber numberWithInt:i]];
}
}
 
[allNumbers removeObjectsInArray:nonPrimes];
return [NSArray arrayWithArray:primes];
}

Kurt the PDF Kitten

Coding Project — PDF search and highlighting framework for iOS apps. Finds occurances of keywords and provides its position and dimensions as drawn on screen.

Kurt the PDFKitten project on GitHub

Marcus Hedenström, 2012.