其中有一个plist,它为带有一些数据的collectionView提供数据源。我将plist放在名为Resources:
的文件夹中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)
}
}
}
}
}