通过数组将对象从Parse转换为核心数据

时间:2016-03-02 17:59:03

标签: arrays swift core-data parse-platform

我有一个tableview,通过queryForTable函数从Parse获取数据。这很好用。我想从Parse获取相同的对象并将它们添加到我以后可以存储在Core Data中的数组中!有谁知道如何做到这一点?我在下面添加了我的代码,以显示我如何将其添加到TableView。

提前感谢您的帮助。 ;)

//MARK: Query for Table with the details
    override func queryForTable() -> PFQuery {

        let discoveryQuery = PFQuery(className: "DiscoveryDetails")
        discoveryQuery.cachePolicy = .NetworkElseCache
        discoveryQuery.whereKey("discoveryID", equalTo: PFObject(withoutDataWithClassName: "Discovery", objectId: "\(varInDDT!.objectId!)"))
        discoveryQuery.orderByDescending("createdAt")
        return discoveryQuery

    }

...

  

//我奇怪地找不到要声明的类型   cellForRowAtIndexPath中显示的值。 PFObject似乎没有   工作要么。也许有一些我对此缺失的东西   对象类型对所有人都是通用的。

 var objectsArray : [String] = []

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {

        //Discovery Items TableViewCell
        var discoveryDetailItemsCell:DiscoveryDetailTableViewCell! = tableView.dequeueReusableCellWithIdentifier("DiscoveryDetailTableViewCell") as? DiscoveryDetailTableViewCell

        if (discoveryDetailItemsCell == nil) {
            tableView.registerNib(UINib(nibName: "DiscoveryDetailTableViewCell", bundle: nil), forCellReuseIdentifier:"DiscoveryDetailTableViewCell")
            discoveryDetailItemsCell = tableView.dequeueReusableCellWithIdentifier("DiscoveryDetailTableViewCell") as? DiscoveryDetailTableViewCell
        }

        //Background Colour of the Cell

        discoveryDetailItemsCell.titleLabel.text = object?.objectForKey("exerciseName") as? String
        discoveryDetailItemsCell.titleLabel.textColor = UIColor.whiteColor()

        discoveryDetailItemsCell.durationAndSetsLabel.text = "\((object?.objectForKey("durationOrSets"))!)"
        discoveryDetailItemsCell.minAndSetLabel.text = "mins"

        discoveryDetailItemsCell.distanceAndRepsLabel.text = "\((object?.objectForKey("distanceOrReps"))!)"
        discoveryDetailItemsCell.kmAndRepsLabel.text = "km"

        discoveryDetailItemsCell.weightLabel.text = "\((object?.objectForKey("weight"))!)"
        discoveryDetailItemsCell.kgsLabel.text = ""

        discoveryDetailItemsCell.dot1.textColor = UIColor.grayColor()
        discoveryDetailItemsCell.dot2.textColor = UIColor.grayColor()

        //Load Images
        let backgroundImage = object?.objectForKey("workoutImage") as? PFFile
        discoveryDetailItemsCell.backgroundImageView.layer.masksToBounds = true
        discoveryDetailItemsCell.backgroundImageView.layer.cornerRadius =  8.0
        discoveryDetailItemsCell.backgroundImageView.image = UIImage(named: "loadingImage")
        discoveryDetailItemsCell.backgroundImageView.file = backgroundImage
        discoveryDetailItemsCell.backgroundImageView.loadInBackground()

       //My Attempt at adding one of the values into an array
       objectsArray  = [(object?.objectForKey("exerciseName"))! as! String]

        return discoveryDetailItemsCell
    }

0 个答案:

没有答案