I have two properties "M" and "m", not the best coding style I know but bear with me. Assignment to these properties in the init method does not function properly. Here's the code in it's entirety:
#import "AppDelegate.h"
@interface Foo : NSObject
@property (nonatomic, assign) int M;
@property (nonatomic, assign) int m;
- (id)initWithM:(int)M m:(int)m;
@end
@implementation Foo
- (id)initWithM:(int)M m:(int)m {
if((self = [super init])) {
self.M = M;
printf("M = %d %d\n", M, self.M);
self.m = m;
printf("M = %d %d\n", M, self.M);
printf("m = %d %d\n", m, self.m);
}
return self;
}
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
Foo *f = [[Foo alloc] initWithM:2 m:1];
}
@end
And here is the output from the printf's:
M = 2 2
M = 2 1
m = 1 0
If I change "M" to "BAR" and "m" to "bar" it works as I would expect. Is there an explanation for this other than being a compiler bug?
Thanks.
@property int M;
@property int m;
both create
- (void)setM:(int)
If you really wanted to have both an m
and an M
property (which you definitely shouldn't) you can use
@property int M;
@property (setter = setLowerCaseM:, getter = lowerCaseM)int m;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With