Thursday, January 10, 2008

I Did Not Know That

Xcode's Cocoa project templates have 2 occurrences of "#import <Cocoa/Cocoa.h>"- One in the prefix file and one in main.m. The behavior of #import means that only the first occurrence actually matters, but then why would I need the second one in main.m? It turns out that in a monochrome world, I don't. But if you're like me and you use syntax coloring at all, deleting the unnecessary #import in main.m(and any other source files) will leave you with not-so-pretty coloring of all the Cocoa bits.

I'm guilty of deleting the unnecessary #import on general principle, and I'm guessing somebody else out there has done this as well.

Update: I'm now unable to reproduce the syntax coloring problem by deleting the unnecessary #import. However, the problem did exist for myself and others, and was fixed by adding the #import back to a source file. I guess the advice here is: If you have coloring issues and the #import is missing, add it back.

2 comments:

Anonymous said...

I stopped using the provided prefix files altogether. I never actually modify them, and for multi-target projects it's an annoying extra detail. (New targets don't share the prefix file by default).

Instead, I just set the prefix file in the build settings (GCC_BUILD_HEADER) to Foundation or AppKit. You still get the benefits of a shared prefix file, but your regular files also still work on their own, and there's no maintenance. (I think that's the original justification anyway; in case the source files are divorced from the prefix header file.)

Anonymous said...

Hmmm... maybe that's the issue I've been having.

Thanks!