Objective-C Forward Ads vs. #imports

Possible duplicate:
@class vs #import

In Objective-C, what are the best practices for using forward declarations (classes or protocols) and #import -ing files? And why are the declarations recommended at all if #import guarantees that the file will not be included more than once? I am thinking about developing applications for iOS in particular, but I assume this applies to Objective-C in general.

+7
source share
1 answer

My rule of thumb is: if a direct declaration is sufficient, I use it. Otherwise, I import the full declaration using #import .

This is mainly due to my experience with large projects, where the careless use of #import (or #include ) can easily lead to a situation where the compiler must compile more than a million lines of code for each file without a header and where minor changes in one header file cause tons recompilation. As a result, compiling the code takes a lot of time.

+16
source

All Articles