Reputation: 4516
finalRestaurantArray
is an array of PFObjects
which contains the array CloseHours
for each object. CloseHours
contains the closing time for each day of the week [0-6].
How can I create an array that contains the value of CloseHours[dayOfWeek]
for each object. If it is Tuesday (let dayOfWeek = 1
) the array should look like:
[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
This is the array of Objects 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
);
}]
Upvotes: 0
Views: 35
Reputation: 1336
Instead of $0.objectAtIndex(dayOfWeek)
try $0[dayOfWeek]
. $0
is now a Swift array of type [String]
and Swift arrays do not have the objectAnIndex:
method.
Upvotes: 1