plist在集合视图中使用模型类

时间:2018-02-23 10:36:49

标签: ios swift uicollectionview plist

我正在制作一个可点击的集合视图来导航下一个视图控制器,但没有数组传递给collectionview单元格,但是编译器读取它。我想要在集合视图中使用模型类的p​​list帮助。

override func viewDidLoad(){
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    if let path = Bundle.main.path(forResource: "NokiaList", ofType: "plist"){
        if let dict = NSDictionary(contentsOfFile: path){
            print(dict)
            self.arrproducts = NSMutableArray(array: dict.value(forKey: "arrproducts") as! NSArray)
        }
        let product = ProductsDetails()
        let dict = self.arrproducts.object(at: 0) as! NSDictionary
        product.Name = dict.value(forKey: "Name") as! String
        product.Image = dict.value(forKey: "Image") as! String
        product.Status = dict.value(forKey: "Status") as! String!
        let arr = NSMutableArray()
        arr.add(product)
        let productNew = arr.object(at: 0) as! ProductsDetails
        productNew.Status = "yes"
        arr.removeObject(at: 0)
        arr.insert(productNew, at: 0)
        self.CollectionViewOutlet.reloadData()
    }

}

0 个答案:

没有答案