@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
Please sign in to leave a comment.
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.
ok.
I though importing was better since the compilation will fail if the header file is missing.
thanks,
tex
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.
ok, then I will do what is preferred :)