0

Code completion doesn't work within #if and #endif

Environment: latest Xcode version: 4.6.2

#if defined(LITE_VERSION)

  //code here has no or very limited auto completion

#endif

The target is set to the lite version, so the marcro LITE_VERSION is actually already defined.

I'v already deleted all the derived data manually. (By the way, the delete derived data button is grey in the organizer's window for this particular project)

If I just add a #define LITE_VERSION in the source code, the code completion will work. However, I think it's a dirty fix and error prone.

This issue persists over one year with various Xcode versions, and now I have more and more codes to write for the lite version, I really appreciate a permanent solution.

P.S: While I are writing this question, I also continue the trouble shooting, and finally I found out the solution, So I made this as a self-answered question. Hopefully, it will help others.

xiang
  • 251
  • 4
  • 9

1 Answers1

1

Edit: Apple confirms this as a bug.

Edit: The code completion just works a while, then stop working, really weird.

Original answer:

Finally I found out the real cause.

It seems the marcro I defined for the lite version works for real compilation, however, while in the editor, the marcro does't work.

So I checked the marcro definition in the building settings, and google for what's the right way to define marcros in xcode, and this link really helps.

That is, I changed the marcro settings from the below: enter image description here

To:

enter image description here

AND clean the derived data again, now it works!

This maybe has something to do with the conversion from GCC settings to LLVM settings.

xiang
  • 251
  • 4
  • 9
  • This above solution actually doesn't work. It seems the editor always stick to the marcro definitions of the paid(non-lite) target. If I add "LITE_VERSION" marcro to the paid target, the code completion then works. I already set the current scheme to the lite scheme, put the lite scheme to the first of the scheme list, put the lite target to the first of the target list, no success yet. So, how to tell the editor to use the macro definition of the right target? – xiang Jul 07 '13 at 16:10
  • It sounds like a bug (probably). Report it to bugreport.apple.com – Robotic Cat Jul 07 '13 at 17:05
  • Yes, it's like a bug. By the way, I just updated the Xcode to the latest 4.6.3, the same problem. – xiang Jul 07 '13 at 18:41
  • For a newly created test project, the behaviour is not stable. Sometimes it sticks to the lite target, sometimes it sticks to the default target, sometimes it works as expected: get macro definitions according to the CURRENT scheme. I submitted a bug report to Apple. – xiang Jul 07 '13 at 18:53