从Object中的Array值创建数组

时间:2015-01-25 05:41:27

标签: objective-c arrays swift

finalRestaurantArray是一个PFObjects数组,其中包含每个对象的数组CloseHoursCloseHours包含一周中每一天的结束时间[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
    );
}]

1 个答案:

答案 0 :(得分:1)

而不是$0.objectAtIndex(dayOfWeek)尝试$0[dayOfWeek]$0现在是类型[String]的Swift数组,Swift数组没有objectAnIndex:方法。