我的iOS应用无法在代码中找到我的plist

时间:2015-08-24 23:49:19

标签: ios swift uicollectionview plist

我在做this tutorial

其中有一个plist,它为带有一些数据的collectionView提供数据源。我将plist放在名为Resources:

的文件夹中

enter image description here

plist项的name属性是要显示的图像的名称,因此这些名称与水果不对应,因为我的图像是衣服图标。此函数不会使它超过第一个if语句。为什么会这样?

 func populateData() {
        if let path = NSBundle.mainBundle().pathForResource(
            "Fruits", ofType: "plist") {
                if let dictArray = NSArray(contentsOfFile: path) {
                    for item in dictArray {
                        if let dict = item as? NSDictionary {
                            let name = dict["name"] as! String
                            let group = dict["group"] as! String

                            let fruit = Fruit(name: name, group: group)
                            if !contains(groups, group){
                                groups.append(group)
                            }
                            fruits.append(fruit)
                        }
                    }
                }
        }
    }

0 个答案:

没有答案