Question

I just create a protocol header file by doing:

File -> New -> File -> (Cocoa Touch) Objective-C Protocol -> Next -> input protocol name -> Next -> choose my Target -> Create

when I trying to create a method list in the protocol header file. I noticed Dynamic Typing doesn't work. When I type "NSStr" in other files, usually a Class list will automatically popup and all classes are marked with colors. why it doesn't work in protocol header file?

BTW, I tried putting protocol code in existing class file, that works. why it doesn't work in separated file?

Some key words will work, such as "void". the popup list will show. but other key words like "NSString" will not be recognized.

My protocol is like this:

#import <Foundation/Foundation.h>

@protocol PanToSwitchViewDelegateProtocol <NSObject>

@end
Was it helpful?

Solution

I just experimented and I see exactly the same thing. I think the problem is that the compiler will not scan the file unless it is imported into a file that is scanned.

If you import your protocol header into a .m file and compile it for luck, you should start getting the autocomplete on NSString.

EDIT

It's clear from the comments on my answer and elsewhere that jazou2012 is under a misapprehension.

Autocomplete has nothing to say about whether a module is correct or not. Autocomplete may fail to find an identifier for several reasons, even if that identifier has been correctly defined. For instance, I was able to replicate Jazou's problem with NSString in a protocol even though Foundation.h was imported.

However, as soon as I imported my protocol header into .m file, the autocomplete started recognising NSString. My guess is that autocomplete only starts indexing files if they are visible to the compiler.

If you want to catch compilation errors, you need to compile the code. If the compiler says "no errors or warnings", your code is OK regardless of what autocomplete says.

OTHER TIPS

Either import into the class header or the implementation file or in another place where it will be visible, like another header of imports or the precompiled header. The protocols in Foundation are visible always because they're imported with Foundation. Cocoa includes Foundation so view classes will include Cocoa protocols. Core Animation and WebKit is not included by default so you need to import those to see any protocols they include.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top