如何用字典创建数组?
我只需要一些帮助来创建一个可以存储多个字典的数组。 我有:
谢谢
NSArray * projects;
NSDictionary *project1;
NSDictionary * project2;
.h.m
projects = /* What should I write here to store the
above two dictionaries in my array. */
,
I just need some help in creating an array which can store multiple dictionaries.
I have :
.h
NSArray * projects;
NSDictionary *project1;
NSDictionary * project2;
.m
projects = /* What should I write here to store the
above two dictionaries in my array. */
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
基本上(这将是正确的或不太正确,具体取决于您的实际代码、声明、属性等)。因为您将
projects
声明为NSArray
,所以您可以执行以下操作:当该变量超出范围时,它会神奇地消失,除非您保留它。
或者,如果您将
projects
声明为NSMutableArray
并创建一个具有属性(retain, nonatomic)
的属性,您可以执行如下操作:有多种方法可以实现您的目标,具体取决于您对阵列的总体需求。
Basically (and this will be right or not quite right depending on you actual code, declarations, properties, etc). Because you declared
projects
as anNSArray
, you could do the following:This variable will go away magically when it goes out of scope unless you retain it.
Alternatively, if you declare
projects
as anNSMutableArray
and make a property with attributes(retain, nonatomic)
, you could do something like this:There are several ways to achieve your goal, depending on your overall needs for the array.
我不确定您正在寻找的内容是否比这更复杂,但是:
应该可行。
如果您想要更复杂的东西,那么这让我知道我会修改我的答案。
I'm not sure if what you are looking for is more complex then this, but:
should work.
If you are after something more complex then this let me know I will revise my answer.