Showing posts with label private method in Objective C. Show all posts
Showing posts with label private method in Objective C. Show all posts

Monday, March 5, 2012

How to define private methods in Objective C ?

Ok, I was checking my backlog emails and I found out an interesting question asked by a user:

How to define private methods in Objective C ?

Now different people do it differently, but one the most popular and easiest route is following:
You have a class MyClass, So you want to define a private method say updateText:(NSString *)value,
Here is how you do it.




#import "MyClass.h"

@interface MyClass() 
-(void)updateText:(NSString *)value;
@end


@implementation MyClass
.
.
-(void)someMethod
{

    [self updateText:@"Reetu"];
}
.
.
.
-(void)updateText:(NSString *)value
{
     myLabel.text=value;

.
@end