Cocoa: what do you call your init parameters so as not to interfere with ivars?

Let's start with an example:

@interface myClass : NSObject {
    NSString * title;
}

-(id)initWithTitle:(NSString*)title;

The compiler does not like this because the init init parameter hides myClass title ivar.

But I do not like these options:

-(id)initWithTitle:(NSString*)t;
-(id)initWithTitle:(NSString*)myTitle;
-(id)initWithTitle:(NSString*)_title;

So to the survey: what is your convention?

+3
source share
3 answers

Some people prefer to call their ivars _titleor title_, and then they can simply use titleas a parameter name in functions. Or you just call it aTitleor newTitle. There is no right or wrong way to do this.

+6
source

I prefer to use -(id)initWithTitle:(NSString *)aTitle;.

+3
source

pTitle, inTitle .

+2

All Articles