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
Go to Xcode > Preferences > Text Editing again. Quit out of Xcode and then relaunch Xcode. Now go to Code completion and check 'Suggest completions while typing'. Try typing library function or enum and enjoy!
From your Xcode menu, select File > New > File... From iOS template options, select Other > PCH file. Name the file <target_name>-Prefix. pch, and then select Create.
Show/hide completions: ⎋ ( Escape ) OR ⌃Space ( Control + Space ) Type some code, use either ⎋ or ⌃Space to toggle auto-complete (I'm hooked on Escape ), and Xcode will offer a few intelligent suggestions to complete your code.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With