[英]How do I create array of dictionary in objective c
I am so far new in iOS. 到目前为止,我在iOS中是新手。 I tried a lot to get an output but didn't get.
我做了很多尝试以获得输出,但是没有得到。 Please help, I want to store data into an
Array
like this format in Objective-C
language: 请帮忙,我想用
Objective-C
语言将数据存储到这种格式的Array
中:
(
{
Appearance = Copper;
Bitterness = 50;
Style = "India Pale Ale (IPA)";
},
{
Appearance = "Jet Black";
Bitterness = 35;
Style = Stout;
},
{
Appearance = Copper;
Bitterness = 25;
Style = "English Brown Ale";
},
{
Appearance = "Deep Gold";
Bitterness = 25;
Style = Bock;
}
)
can anyone please help me out. 谁能帮帮我。
Here is the way to create Array
of Dictionary
: 这是创建
Dictionary
Array
的方法:
Objective C : 目标C:
NSArray *arrTemp = @[
@{@"Appearance" : @"Copper",
@"Bitterness" : @(50),
@"Style" : @"India Pale Ale (IPA)"},
@{@"Appearance" : @"Jet Black",
@"Bitterness" : @(35),
@"Style" : @"Stout"},
@{@"Appearance" : @"Copper",
@"Bitterness" : @(25),
@"Style" : @"English Brown Ale"},
@{@"Appearance" : @"Deep Gold",
@"Bitterness" : @(25),
@"Style" : @"Bock"}
];
Swift : 斯威夫特:
let arrTemp: [[String:Any]] = [
["Appearance" : "Copper",
"Bitterness" : 50,
"Style" : "India Pale Ale (IPA)"],
["Appearance" : "Jet Black",
"Bitterness" : 35,
"Style" : "Stout"],
["Appearance" : "Copper",
"Bitterness" : 25,
"Style" : "English Brown Ale"],
["Appearance" : "Deep Gold",
"Bitterness" : 25,
"Style" : "Bock"]
]
Dictionaries are initialized like this: 字典的初始化如下:
NSDictionary *dict = @{ key : value, key2 : value2};
Arrays are initialized like this: 数组是这样初始化的:
NSArray *array = @[Object1, Object2]
So you can create Dictionaries object as per your data and add to array like 因此,您可以根据数据创建Dictionaries对象,然后将其添加到数组
NSArray *array = @[DicObject1, DicObject2]
Any doubt plz comment. 如有任何疑问,请评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.