Strange object C error, properties are not case sensitive?

I have two properties "M" and "m", and not the best coding style that I know, but carry with me. Assigning these properties in the init method does not work as expected. Here is the whole code:

#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 result of printf output:

 M = 2 2 M = 2 1 m = 1 0 

If I change β€œM” to β€œBAR” and β€œm” to β€œbar”, it will work as I expected. Is there any explanation for this other than a compiler error?

Thanks.

+7
source share
1 answer
 @property int M; @property int m; 

both create

 - (void)setM:(int) 

If you really wanted to have both the m and m property (which you definitely don't need), you can use

 @property int M; @property (setter = setLowerCaseM:, getter = lowerCaseM)int m; 
+12
source

All Articles