Nate
Nate

Reputation: 13252

Is the ivar required for properties where @synthesize propertyName = _propertyName;

In the following example, is the line NSObject *_propertyName; required?

.h

@interface  ClassName
{
    NSObject *_propertyName;
}

@property (nonatomic, retain) NSObject *propertyName;

@end

.m

@implementation  ClassName

@synthesize propertyName = _propertyName;

@end

I find that if I exclude NSObject *_propertyName; but keep @synthesize propertyName = _propertyName; everything works. Here's an example of what I'm talking about:

.h

@interface  ClassName

@property (nonatomic, retain) NSObject *propertyName;

@end

.m

@implementation  ClassName

@synthesize propertyName = _propertyName;

@end

I've tested and seen that the property still works. I nearly always see code that includes the line NSObject *_propertyName;. Is there something I'm missing here?

Upvotes: 0

Views: 162

Answers (1)

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

You're not missing anything. Starting with the newer runtimes (newer iOS Simulator, x86_64 and ARM) you no longer need to manually declare an ivar. Prior to that on i386 and PPC you had to manually declare your ivars.

Upvotes: 3

Related Questions