One code base for Snow Leopard and Leopard

Background

I am a developer who is in the process of creating an application for Mac. I'm going to take on the Snow Leopard. So far I have been building on Leopard. I have been developing Cocoa for about a year not very intensively.

I read a lot about Snow Leopard and Grand Central Dispatch in particular. I know that it uses blocks, but I did not understand how blocks work or how Grand Central Dispatch works.

My question

What is the best way to develop one code base for Snow Leopard and Leopard, while maximizing the new multithreading capabilities in Snow Leopard?

NSOperationQueue

My instinct is not to deal with GCD directly in my code, but when something needs to be queued, use NSOperationQueue, as I read from Mike Ashes Q & A sessions that in Snow Leopard, NSOperationQueue is in full least takes advantage of the GCD and crasher that he discovered at Leopard are now fixed.

Manual flow control

However, when it comes to managing specific background threads, is there a way to take advantage of the thread management tools in Snow Leopard without breaking any problems in Leopard? Or do people recommend that I have different goals for each OS with several different classes in each? It would seem to me that a nightmare for service is just waiting to happen.

Or maybe I just need to live without a fully optimized application for Snow Leopard and adhering to +(void)detachNewThreadSelector:toTarget:withObject: or something like that.

What do people think?

+6
objective-c cocoa osx-snow-leopard grand-central-dispatch
source share
2 answers

Your impression of GCD is correct. In fact, any API that uses blocks is missing unless you disable this code to work only on Snow Leopard. This makes sense if the code is designed to support functions that are available only on Snow Leopard, but if it is a function that you will also support on Leopard, you can only use Leopard code in all cases by adding a special parameter to Snow Leopard path that does not gives no visible improvements to the user, just complicates your code and increases your overhead.

This is especially true for features such as flow control or GCD. Changes there require significant architecture, it is not easy:

 if (snowLeopard) { [NSSnazySnowLeopardClass doSomething]; } else { [NSBoringLeopardClass doSomethingEquivalent]; } 

In general, if the changes are so simple that Apple processes them inside the class without changing the API. In other words, the question is not whether you can use the simpler flow control code in Snow Leopard, but because when you have to make a hard version for Leopard anyway. An additional code path is an additional code path, and until you can refuse to support Leopard using significantly different APIs on Snow Leopard (even if they are easier to use than Leopard), this is just an additional work.

I would think if you really want to target Leopard. The disposal of Snow Leopard was fair, Snow Leopard is a cheap upgrade, and due to API changes there will be a lot of direct pressure on users from small developers who deal only with Snow Leopard. The only group of users who will remain on Leopard for a long time are those who are not technically savvy (who are unlikely to install a lot of third-party software), and those who are still using PPC Macs (who have not bought a new Mac after 3 years, so probably don't buy a lot of software). If this is an application that you think is about to go in 3-9 months, I would say that switching to Snow Leopard is probably a reasonable option and will significantly reduce your development and testing costs.

+9
source share

One way would be to understand which APIs in Leopard have been changed in Snow Leopard to use GCD. For example, NSOperation and NSOperationQueue in Leopard work the way they always are. However, they were rewritten in Snow Leopard to use the GCD from below. Voila. Instant update for your users 10.6.

Another option would be to use something like PLBlocks and compile the GCD yourself into your code. I have no idea if this will work, but it might be worth it. =)

+2
source share

All Articles