Property synthesis trouble - 32 vs 64 bit builds
Property synthesis trouble - 32 vs 64 bit builds
- Subject: Property synthesis trouble - 32 vs 64 bit builds
- From: Jonathan Taylor <email@hidden>
- Date: Tue, 05 Jul 2016 12:36:18 +0100
Hi all,
I have a problem with property synthesis in my code, which I hope somebody can advise on. I find I have to write different property synthesis code for 32- or 64-bit builds in order to avoid compiler errors.
A minimal demonstration of the problem can be found below - build as part of a fresh project on Xcode 5 or 6, with ARC disabled. It surprises me that I have to write different synthesis code for 32- or 64-bit builds - and this then makes me worry that I am doing something more fundamentally wrong. Can anyone comment (or explain)?
[I appreciate that this code may be old-fashioned in style - I am not even sure what is or is not the recommended style these days. It seems to work though - and, importantly, as far as I can tell the synthesized property myFlag on MutableSettings *does* map to the same backing variable, even on a 64-bit build where I am not able to specify the backing variable in the synthesis statement]
Cheers
Jonny
@interface ImmutableSettings : NSObject
{
BOOL _myFlag;
}
@property (readonly) BOOL myFlag;
@end
@interface MutableSettings : ImmutableSettings
@property (readwrite) BOOL myFlag;
@end
@implementation ImmutableSettings
-(id)init
{
if (!(self = [super init]))
return nil;
_myFlag = true;
return self;
}
@synthesize myFlag = _myFlag;
@end
@implementation MutableSettings
// This is very odd - I get errors on 64-bit builds if I specify a backing variable for synthesis,
// but I get errors on 32-bit builds if I *don't* specify a backing variable!?
#if defined(__x86_64__)
// On 32-bit builds I get an error here:
// "Synthesized property 'myFlag' must either be named the same as a compatible instance variable or must explicitly name an instance variable"
@synthesize myFlag;
#else
// On 64-bit builds I get an error here:
// "Property 'myFlag' attempting to use instance variable '_myFlag' declared in super class 'ImmutableSettings'"
@synthesize myFlag = _myFlag;
#endif
@end
_______________________________________________
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