Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只是想知道 [[UIImageView new] init] 和 [[UIImageView alloc] init] 有什么区别。
[[UIImageView new] init] 中是否也分配了内存?
+ new等价于+ alloc后跟- init,所以
+ new
+ alloc
- init
UIImageView *iv = [[UIImageView alloc] init];
和
UIImageView *iv = [UIImageView new];
是正确的(和等价的)并且
UIImageView *iv = [[UIImageView new] init];
是错误的,因为它调用- init了两次。