1

When a method is declared in .h file is detected by intelisense and the warnings are not raised, when the method is used in .m file.

When a method is declared only in .m file, the intelisense doesn't detect it if is declared below the method where is being used.

To avoid the warnings there is a flag in xcode, but I prefer don't disable it.

There is any way to declare the methods in .m in order to be detected by intelisense and without the warning?

Thanks.

2 Answers 2

4

Two ways to fix it:

Either: Use a class extension to declare private methods at the top of the .m file:

@interface Foo ()

- (void)privateMethod;

@end

Or: Upgrade to Xcode 4.3.1, which contains a more recent version of clang. This newer version of the compiler does not need previously declared methods to call them in the same compilation unit.

Class extensions are still good for compatibility or to declare private properties, though.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use a category to declare additional methods on a class.

For instance, adding this at the top of your .m file:

@interface MyClass (PrivateCategory)

-(void)foo;
-(void)bar;

@end

will let Xcode know that MyClass additionally responds to foo and bar. The (PrivateCategory) tells the compiler that you're adding methods that should be "grouped" under the category PrivateCategory. You can pick whatever name you want, or even no name at all (although an "anonymous category" has slightly different semantics).

3 Comments

Thanks for the answer! But directly in the implementation file, is it possible?
Since the introduction of class extensions there's a dedicated mechanism for private declarations which should be preferred.
@NemeSys, yes. Any declaration can go in a .m file. You usually put global declarations in .h file because you can include these declarations in other files; but whatever is valid in a .h file is also valid in a .m file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.