我想创建一个像这样的类型:
NSDictionary
但我不知道该怎么做。
的初始化如下:
"zones":
{
{
"zoneId": "1",
"locations":
{
{
"locId": "1",
"locZoneId": "1",
"locLatitude": "33.68506785633641",
"locLongitude": "72.97488212585449"
},
{
"locId": “2”,
"locZoneId": "1",
"locLatitude": "33.68506785633641",
"locLongitude": "72.97488212585449"
},
{
"locId": “3”,
"locZoneId": "1",
"locLatitude": "33.68506785633641",
"locLongitude": "72.97488212585449"
},
}
}
}
的初始化如下:
NSDictionary *dict = @{ key : value, key2 : value2};
NSArray *array = @[Object1, Object2]
为
key
,而 NSString
为 value
。您应该始终尽可能地设置类型,因为通过将其设置为强类型,编译器将阻止您犯常见错误,并且它在 Swift 中效果更好:
NSNumber
但是在上面的例子中,我们需要在字典中存储一个数组,所以它将是:
NSDictionary<NSString *, NSNumber *> *numberDictionary;
允许值是任何类型。