开发者

private methods in cocoa? [duplicate]

This question already has answers here: 开发者_StackOverflow中文版 Closed 11 years ago.

Possible Duplicate:

Best way to define private methods for a class in Objective-C

Hi, Can i have private methods for any class in a cocoa application? if yse, how?


Yes you can!

in your *.m file (Implementation)

#import "MyClass.h"

@interface MyClass() 
- (void)privateMethod();
@end 

@implementation MyClass

- (void)dealloc {
    [super dealloc];
}

- (void)privateMethod
{
   NSlog(@"myPrivateMethod");
}
@end


If program Java, for example, I'd say to you that private methods are not simple to implement.

To implement them, you should implement, in the .m file, interfaces containing the signature of those methods you want to be private. Since imports "always" regards to .h files, this solution serves as private method implementation solution.

Resuming: use .h to expose your public methods. Use interfaces inside the .m to enable methods to be used as private.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜