快速遍历plist

问题描述 投票:-1回答:1

大家好,我目前正在尝试遍历这样设置的plist:

enter image description here

我正在使用的代码:

    letterPoints = NSDictionary(contentsOfFile: Bundle.main.path(forResource: "LetterPoints", ofType: "plist")!)

    for (myKey, myValue) in letterPoints {
        for (key, value) in myValue as NSDictionary {
            let x = value["Item 0"] as NSNumber
            let y = value["Item 1"] as NSNumber
            // lastPoint: CGPoint = CGPoint(x: x.integerValue, y: y.integerValue)
            println("x: \(x); y: \(y)")
        }
    }

但是我在循环的第一行中遇到了错误:for-in循环需要'NSDictionary?'符合“顺序”;您是说要拆开可选包装吗?

我从loop through nested NSDictionary in plist using swift中获取了代码,它似乎与我的结构化plist相同,因此不知道为什么它不起作用。遍历我的plist的最佳方法是什么?

ios swift nsdictionary swift-optionals
1个回答
0
投票

letterPoints安全解开if let

© www.soinside.com 2019 - 2024. All rights reserved.