我是障碍物在Objective-C中,我想从Objective-C的角度理解指针背后的概念。给定下面的代码,我希望3语句显示相同的结果或至少显示sam内存地址。至少因为,指针
meAsImpl refers/points/observs the memory location of the user-defined object MeAsImpl
Hence, the 3 NSLog statement should display the same results
代码的输出如下:
<MeAsImpl: 0x600000194120>
<MeAsImpl: 0x60000019f240>
<MeAsImpl: 0x60000019f240>
[请让我知道为什么第一个值不同于后两个值
代码:
MeAsImpl *meAsImpl = [[MeAsImpl alloc] init];
NSLog(@"%@", meAsImpl);
NSLog(@"%@", MeAsImpl.alloc);
NSLog(@"%@", MeAsImpl.alloc.init);
每次调用alloc
时,都会为调用者分配新的内存地址。 init
刚刚初始化了已经分配的内存,所以地址不会在init
上更改]