0

It's the first time I move with Parse. Parse did the pod, I import the class in Bridging-Hearder and declared the Delegate (swift) the Id and the clientKey I will use. Let my doubt, what I have to do to get this data from Parse and insert them in a TableView?

1
  • Parse iOS guides can help you greatly as they already added swift code example along the ObjC examples. parse.com/docs/ios_guide Commented Sep 5, 2014 at 14:53

1 Answer 1

3

ok the first thing you should do is in the AppDelegate set id parse

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

    Parse.setApplicationId("ID-PARSE", clientKey: "KEY-PARSE") return true }

create a object

var message:PFObject = PFObject(className:"CLASS-NAME")
    message["NAME ROW IN YOUR DATABASE PARSE"] = messageBox.text as String
    message["User"] = PFUser.currentUser()
    message.saveInBackground()

load data parse

func loaddata()
{
    var dataParse:NSMutableArray = NSMutableArray()
    var  findDataParse:PFQuery = PFQuery(className: "NAME ROW IN YOUR DATABASE PARSE")

    findDataParse.findObjectsInBackgroundWithBlock{
        (objects:AnyObject[]!, error:NSError!)->Void in

        if (!error){
            for object:PFObject! in objects
            {
                self.dataParse.addObject(object)
            }
        }
        //// add data into array  
        let array:NSArray = self.dataParse.reverseObjectEnumerator().allObjects
        self.dataParse = array as NSMutableArray

        self.tableView.reloadData()
    }

}

now table

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int
{
    return 1
}


override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
    return self.dataParse.count
}


override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?
{

    let cell:CustomCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath!) as CustomCell

    let cellDataParse:PFObject = self.dataParse.objectAtIndex(indexPath!.row) as PFObject

    cell.mensajeBox.text = cellDataParse.objectForKey("NAME ROW IN YOUR DATABASE PARSE") as String return cell }

i hope this help !

Sign up to request clarification or add additional context in comments.

Comments

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.