我有一个PFObjects
数组。如何访问特定键的值。例如,我想访问每家餐馆的"Name"
。
我在想的是:
restaurantArray["Name"]
,但我需要指定数组索引吗?
[<Restaurant: 0x7feb9252cfc0, objectId: LA74J92QDA, localId: (null)> {
Name = "Restaurant 1";
City = "New York";
Closed = 1;
Country = "United States";
FoodType = Japanese;
}, <Restaurant: 0x7feb926afa00, objectId: 0aKFrpKN46, localId: (null)> {
Name = "Restaurant 2";
City = "San Francisco";
Closed = 1;
Country = "United States";
FoodType = Italian;
}]
答案 0 :(得分:1)
是的,您需要为要获取其名称的餐馆指定数组索引,例如restaurantArray[0].objectForKey("Name")
如果要将所有餐馆的所有名称提取到单独的数组中,您可以执行以下操作
let namesArray = restaurantsArray.map { $0.objectForKey("Name") }