@class vs #import

Hi,
When an object is not known in a class, AppCode offers to fix it with Opt+Enter. Sometimes it will add @MyClass to the .h file and sometimes it will actualy #import the class. For example, in this code, AppCode will predefine the MyUITableCell instead of importig it.

@interface MyViewController : UITableViewController {     MyUITableCell *myUITableCell; }



In this case, I would expect a simple #import MyUITableCell. Is this normal ?

thanks
4 comments
Comment actions Permalink

Predefining classes in headers is preffered way. Only classes that are really needed like superclass or protocol need to be imported.

The reason is, that predefining saves a necessity to load many "unnecessary" headers when your header is imported elsewhere. This is mostly optimization. But it needs to be used to resolve circular dependencies.

0
Comment actions Permalink

ok.
I though importing was better since the compilation will fail if the header file is missing.

thanks,
tex

0
Comment actions Permalink

Correct, predefining classes in headers is preffered way. But if you still want AppCode to insert imports instead of @class, there's an option in Preferences | Editor | Auto Import.

0
Comment actions Permalink

ok, then I will do what is preferred :)

0

Please sign in to leave a comment.