views:

67

answers:

1

In my iOS adventures, I got really into blocks, because they were necessary for the UIViewAnimation to "Animate With Blocks" which is the recommended way to do UIView animations. Of course, this results in code that is not backwards compatible. I realize this question has a subjective component, but at what point would using the iOS 4.0 code only be a good idea? Or would differential code be a good idea, and how would that be achieved in objective-c?

I'm now faced with redoing my code for iOS 3.0, which is a painful task: should I just keep my "blocks" code around until the world advances?

+2  A: 

See Plausible Blocks for a port of the blocks runtime to 10.5/iPhone OS 3. It might be easier than rewriting your code, though you'll have to implement and add the relevant animation methods to UIView's metaclass on 3.0 (hint: class_addMethod()).

I don't think we'll be dropping OS 3 support for another 6-9 months, depending on adoption (especially considering that the iPad is still stuck on 3.2.1).

There's also no easy way to replicate setAnimationWillStartSelector: with the block-based animation API. I've used it to sync sounds to animations (you can't just play the sound, because the animation doesn't start until after view layout/image loading finishes).

tc.
Great answer and you hit some points I didn't know about at all, like the absence of the `setAnimationWillStartSelector`... I really don't get the obsession with blocks. On one hand they're so much cuter, but on another, they almost insist on hard-to-read inline code. Obviously you can call methods...
Yar
Another question is: how long will the deprecated methods stick around (judging from historically similar cases)?
Yar
"Normal" animations haven't actually been deprecated yet, and I'd give it until at least iOS 5 (i.e. when they might drop OS 3 support from the SDK) before it's deprecated, and a while after that before it's removed. If you go for a warnings-free build, then you'll have a lot of #ifs in your code anyway (because simulator builds set min OS = base SDK), so it should automatically stop using deprecated functions when you drop the relevant base SDKs anyway,
tc.