我有两个属性“M”和“m”,这不是我所知道的最好的编码风格,但请容忍我。在 init 方法中对这些属性的赋值不能正常工作。这是完整的代码:
#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
这是 printf 的输出:
M = 2 2
M = 2 1
m = 1 0
如果我将“M”更改为“BAR”并将“m”更改为“bar”,它会按我的预期工作。除了编译器错误之外,还有其他解释吗?
谢谢。