Friday, March 23, 2012

My favorite feature in Xcode 4.3


My favorite feature in Xcode 4.3 (LLVM 3.1) is that you no longer need to use forward declarations for private Objective-C methods.

Before this version if you called a private Objective-C method you would get a compiler error if you didn't do one of the following:

1) Move the implementation of the private method above all the calls to it in the source file.
2) Forward declare the method via a category or extension.

#1 sucks because you end up with less readable code. Low level "helper" methods bubble up to the top while the more general methods get pushed to the bottom. Ideally (I think) your source code should be organized and read like a newspaper. The high level concepts / methods should be at the top and the lower level methods on which they depend should be below it.

#2 sucks because the forward declarations are extra work which feel unnecessary and seems to break the DRY principle.

With Xcode 4.3 the restriction has been lifted.

You no longer need to declare private methods and you can call the methods from any where in the source file.

Over the past few years I've been super impressed with how quickly Apple has evolved Objective-C. It's finally starting to look modern. ;-)

My hope for WWDC this year is death to the .h file.

Happy coding.


No comments: