finalRestaurantArray
是一个PFObjects
数组,其中包含每个对象的数组CloseHours
。 CloseHours
包含一周中每一天的结束时间[0-6]。
如何为每个对象创建一个包含CloseHours[dayOfWeek]
值的数组。如果是星期二(let dayOfWeek = 1
),则数组应如下所示:
[0015, 2350]
//create array of CloseHours
let initialCloseRestaurantHours = finalRestaurantArray.map { $0.objectForKey("CloseHours") as [String] }
//get the close hour for given day
let closeRestaurantHours = initialCloseRestaurantHours.map { $0.objectAtIndex(dayOfWeek) as String }
//Error: [string] does not have a member named objectAtIndex
这是对象数组finalRestaurantArray
[<Restaurant: 0x17411aca0, objectId: LA74J92QDA, localId: (null)> {
Name = "First One";
CloseHours = (
0005,
0015,
0025,
0035,
0045,
0055,
0065
);
}, <Restaurant: 0x17411b480, objectId: 0aKFrpKN46, localId: (null)> {
Name = "Second One";
CloseHours = (
0015,
2350,
2350,
2350,
2350,
2350,
2350
);
}]
答案 0 :(得分:1)
而不是$0.objectAtIndex(dayOfWeek)
尝试$0[dayOfWeek]
。 $0
现在是类型[String]
的Swift数组,Swift数组没有objectAnIndex:
方法。