1

Given the following in-progress C++ code:

if (true)
    std

, as soon as I enter the first colon (:) of the scope resolution operator (::), XCode oddly inserts some square brackets, and my code looks like this:

if [(true)
    std:]

This is really annoying, and it can't figure out why it's doing it. At the moment it's doing it in some files but not others.

Cam Jackson
  • 11,860
  • 8
  • 45
  • 78

2 Answers2

3

It looks like it's trying to help you with Objective C syntax.

At a guess, the files where it's trying to do that have an extension indicating that what you're writing is Objective C. The files where it's not doing it are those that have an extension indicating that they contain C++ instead.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • Yeah, it's doing it to my header files. Any idea how to tell it that my .h files are C++, not Obj-C? – Cam Jackson Feb 20 '13 at 03:59
  • 1
    @CamJackson: http://stackoverflow.com/questions/10441509/getting-xcode-to-recognise-c-header-files-without-the-h-extension-openscen looks like it might be handy about now. – Jerry Coffin Feb 20 '13 at 04:02
  • Who would have guessed that; neat explanation JerryCoffin and @Ric – Arcturus Feb 20 '13 at 04:13
  • @CamJackson: The only other suggestion I can think of right off would be to try some of the obvious "C++ Header" extensions like `.hpp`. – Jerry Coffin Feb 20 '13 at 04:14
  • Actually, it looks like I just needed to restart Xcode after doing what was suggested in the answer you linked (changing the 'File Type' for each .h file in the project). – Cam Jackson Feb 20 '13 at 04:20
1

It's trying to be nice and complete the Obj-C syntax.

object method

Adding a colon next turns into

[object methodWithParameter:(parameter) ]
Ric
  • 8,615
  • 3
  • 17
  • 21
  • Yeah this seems right. I just noticed, it's only doing it for my header files, and not cpp files. So I need to tell it that I'm writing C++ headers, not Obj-C headers. Any idea how to do that? – Cam Jackson Feb 20 '13 at 03:57