2

I am adding a new protocol to my project but XCode does not recognize the code. I already have other protocols in the same project without any problems but this time the funny thing is the color of the code is not the right one and the automatic text helper is not recognizing the language.

For example in a protocol the code appear like that:

#import <Foundation/Foundation.h>

@protocol URLGetDelegate <NSObject>
@required

@optional

- (void)setWeather:(NSArray*) data;
- (void)setChemists:(NSData*) data;

@end

Then NSObject appear in purple, however in the new protocol the NSObject appear in black and when I type code, NSO... XCode does not offer me the words NSObject automatically.

#import <Foundation/Foundation.h>

@protocol CompanyDelegate <NSObject>

@end

Any help?

Thanks

protocol working

protocol working text popup

protocol not working

Laure_f_o
  • 628
  • 1
  • 7
  • 15
  • I don't understand your question; you say `NSObject` appears in purple and then black but there is only one reference to `NSObject`. – trojanfoe Feb 03 '13 at 22:46
  • Sorry, it is difficult to explain. The thing is that XCode does not recognize the new protocol because it is not find in other classes when I try to import. It is like XCode does not recognize the definition of it and comparing the file with other protocol definition in the same project the text is not properly paint in color according with the text paterns. For example, as you see in the code above NSObject appear in blue, because the text parten understand that it is a class name. – Laure_f_o Feb 04 '13 at 13:30
  • The same in XCode the color for a class name in the defination is in purple: @protocol CompanyLayoutDelegate , so NSObject appear in purple normally, however in the new protocol appear en black, and when I try to add code the help text box does not appear showing the typical coincidences according with what you are typing. Thanks for your help it is dificult to explain and I guess to understand what I am saying. – Laure_f_o Feb 04 '13 at 13:31
  • Can you post the complete header file please? – trojanfoe Feb 04 '13 at 13:43
  • it is only what you see. I added some picture to explain better... – Laure_f_o Feb 04 '13 at 13:59
  • OK, looks good. And where is `NSObject` only appearing in black? Also as an aside you must tell me the name of the font you are using! **EDIT**, sorry I see now (`CompanyDelegate`). Hmm, I don't know to be honest; does the delegate actually work as it could be one of Xcode's numerous little bugs... – trojanfoe Feb 04 '13 at 14:15
  • This is happening in the new protocol I try to define/add to the project. The font is the XCode editor font, I do not know it. The problem it is not visual, I am trying to see what it the problem with XCode, a side-effect is the visual and auto-complete functionality effect that I think it is symptom of what is happening. – Laure_f_o Feb 04 '13 at 14:21
  • Sorry this differences is because I try to add the protocol with a different name to do some tests. I correct it to avoid misunderstandings – Laure_f_o Feb 04 '13 at 14:26
  • I don't think I can help you; I don't see anything obviously wrong with your code. – trojanfoe Feb 04 '13 at 14:27
  • thanks anyway for your time. it is really weird nad making me getting crazy.... – Laure_f_o Feb 04 '13 at 14:28

1 Answers1

1

What the Laure_f_o is referring to is the lack of standard auto completion and text colorization that happens in XCode; essentially XCode refusing to recognize a newly added protocol as such. So when you try and add it to a class and declare that class as subscribing to that protocol, you get a build error.

I just had the exact same sort of problem: other protocols in my project that work fine, but when trying to add a new one XCode just would not recognize it at all. This is all for XCode 4.6.2

What finally solved it for me was the following (based on Javy's advice here: Xcode Not Immediately Recognizing New Classes (iOS)):

1.) Clean Project

2.) Close project (but not XCode)

3.) Open Organizer in Xcode (under the Window menu)

4.) Select "Projects" tab

5.) Delete "Derived Data" (if you have saved snapshots, you'll have to delete those first)

6.) Quit XCode and restart computer

7.) Reopen project and clean it again

8.) Import the problem protocol into a class and declare that class as subscribing to it

Then, and only then, did I finally get the protocol in question to start behaving as such and didn't get build errors trying to use it in classes.

Community
  • 1
  • 1
paulmrest
  • 414
  • 4
  • 14