2
votes

I started out thinking I wanted to test or detect if iOS was version 4.x so I would know I could use Grand Central Dispatch to run a concurrent thread. If it was less than iOS 4 I would run the code but not as a thread and take the hit. But in reading at stack overflow I read -

---- "You should probably avoid asking about the system version altogether. A better design would ask about a specific feature. For instance: if (NSClassFromString(@"UIPrintInfo")) would tell you if the current device supports the printing API,available in 4.2 or higher. That way you can plan your code to use a feature if it's available, on not based on the OS version."

That makes sense. So instead of testing for iOS 4, what code-safe method would I use to detect Grand Central Dispatch support ?

1

1 Answers

4
votes

You can check to see if a function exists at runtime by comparing it to NULL like this:

if (dispatch_async != NULL) {
    NSLog(@"We have GCD");
}
else {
    NSLog(@"We don't have GCD");
}

Note: I haven't actually tested this.