Re: Private Methods
Re: Private Methods
- Subject: Re: Private Methods
- From: email@hidden
- Date: Fri, 22 Feb 2008 12:23:50 +0100
On 22 Feb 2008, at 12:00, Philip Bridson wrote:
How do I make a method private?
I have tried putting @private before the method that I want to make
private but the compiler flags a parse error. I read the
documentation and I can only find reference to private member
variables. I want to make sure that a method can only be accessed
via another method in the same class. Is this possible in Objective-
C or do I need to write this class in C++?
No, you can't declare methods private in an interface.
What you can do, in your .m file is declare a private interface to
your object.
E.g in MyObj.h
@interface MyObj : NSObject {
}
-(void) onePublicMethod;
@end
In MyObj.m
@interface MyObj(PrivateStuff)
-(void) aPrivateMethod;
@end;
@implementation MyObj
-(void) aPrivateMethod
{
// Do something
}
-(void) onePublicMethod
{
[self aPrivateMethod];
}
@end
As with all Obj-C stuff though, if someone finds out about your method
signature, then there is nothing to stop them calling it.
Matt
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden