NSMutableArray不添加对象 [英] NSMutableArray does not add objects

查看:88
本文介绍了NSMutableArray不添加对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为,我犯了一个非常基本的错误,但是我使用的是 NSMutableArray ,因此某种程度上它没有添加对象,我将其发送给了它。我有一个属性(并合成)

I think, I am doing a pretty basic mistake, but I am using an NSMutableArray and this somehow doesn't add the object, I'm sending it its way. I have a property (and synthesize)

@property (nonatomic, strong) NSMutableArray *kpiStorage;

然后:

ExampleObject *obj1 = [[ExampleObject alloc] init];
[kpiStorage addObject:obj1];
ExampleObject *obj2 =  [[ExampleObject alloc] init];
[kpiStorage addObject:obj2];

NSLog(@"kpistorage has:%@", [kpiStorage count]);

并且总是在控制台中返回(空)。我误解了什么?

and that always returns (null) in the console. What am I misunderstanding?

推荐答案

确保为kpiStorage分配了内存。

Make sure you allocated memory for kpiStorage.

self.kpiStorage = [[NSMutableArray alloc] init];

这篇关于NSMutableArray不添加对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆