0

I want to let users search from spotlight for my app. I have a PFQueryTableViewController with 500 rows. In Parse the searchable info saved as String with total of 500 different rows. So to able to index rows which is a String i need an array for keywords and such. But i don't know how can i convert query or print it as array.

To Summarize: I have 500 rows of string and i want them to print as an array but could not able to.

Thanks.

My query func:

 override init(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)
    }
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!

        self.parseClassName = "myClassName"
        self.textKey = "myColoumnName"
        self.pullToRefreshEnabled = true
        self.paginationEnabled = false
    }
    override func queryForTable() -> PFQuery {
        var query = PFQuery(className: "myClassName")

        query.cachePolicy = .CacheThenNetwork
        query.orderByAscending("myColoumnName")
        query.limit = 1000
        return query
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> myPFTableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier("mySegue") as! myPFTableViewCell!
        if cell == nil {
            cell = myPFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "mySegue")
        }
        if let myString = object?["myColoumnName"] as? String {
            cell?.myLabel?.text = myString
        }
        if let myString2 = object?["myColoumnName2"] as? String {
            cell?.myLabel2?.text = myString2
        }

        return cell
    }
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "mySegue2" {
            var detailScene = segue.destinationViewController as! myViewController
            if let indexPath = self.tableView.indexPathForSelectedRow {
                let row = Int(indexPath.row)
                detailScene.currentObject = (objects?[row] as! PFObject)
            }
        }
    }

1 Answer 1

1

When using a PFQueryTableViewController, all of the results of the query are stored in the objects array. This is an array of PFObjects, so you will want to create a function to create your search terms array using the properties of your PFObjects. It could be along the lines of this:

if let objectsArray = objects as [PFObject] {
    for object in objectsArray {
        stringArray.append(object["myColoumnName"] as? String)
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you that command made my array filled with parse data but the problem it never stops to append and it goes to infinity until i stop the app
It is probably being called multiple times. You will only want this to be called once assuming that the data is not changing often. If the data on Parse does change often and you need to update the array, remove all of the old values using stringArray.removeAll(keepCapacity: false) before adding the new ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.