gpt4 book ai didi

objective-c - 调用 [[.. alloc] init] 时丢失对象

转载 作者:行者123 更新时间:2023-12-04 06:36:58 25 4
gpt4 key购买 nike

我在调用 alloc/init 时遇到一个奇怪的问题:

当我打电话时:

Card *card = [[Card alloc] init];
return card; //here debugger reports that card is an NSMutableArray*, not a Card*

但是,如果我打电话:
Card *card = [Card alloc];
[card init];
return card; //here debugger reports that card is Card*

卡被声明为
@interface Card : NSObject { ...

我在我的代码中经历过与其他对象分配完全相同的模式。就好像对象在返回之前被释放,或者堆栈被踩到了。

我知道我应该一起使用 alloc/init,但是我遇到了这个问题。

最佳答案

您的 init函数返回 self ?我的猜测是它不是,这可能是你的问题。

关于objective-c - 调用 [[.. alloc] init] 时丢失对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4764232/

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