gpt4 book ai didi

ios - Objective C 中的 NSArray - 它包含什么

转载 作者:行者123 更新时间:2023-11-29 10:48:56 25 4
gpt4 key购买 nike

当我有这样的代码时:

Fruit *fruit= [[Fruit alloc] init];

// This is effectively two different things right, one is "fruit" - the pointer, and another thing is the object it is pointing to (the one that was allocated using alloc/init) - though not directly visible

当我将其添加到 NSArray 时:

[myArray addObject: fruit];

添加到数组中的是实际上是一个指向 Fruit 类对象的指针,对吧?

最佳答案

是的,指针副本,它指向一个有效的已初始化对象,因此以下不会导致问题(至少在 ARC 下):

Fruit *fruit= [[Fruit alloc] init];
[myArray addObject: fruit];
fruit = nil; // OK, array still contains a valid Fruit object

关于ios - Objective C 中的 NSArray - 它包含什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21256524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com