swift
swift

Reputation: 75

Getting data from parse dash to an array

I have strings that are set up in my class on parse, how do I pull those down in to an array.

I don't have any of my own code at the moment. I have found stuff that is in php or php but I cannot find anything in swift.

var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
  (gameScore: PFObject!, error: NSError!) -> Void in
if error == nil && gameScore != nil {
  println(gameScore)
} else {
println(error)
  }
 }

I don't think its that because that is just retrieving an object.

In short is there a way to take Class > String and get all of the data in the column put into an array in my .swift?

Upvotes: 0

Views: 191

Answers (1)

user1555112
user1555112

Reputation: 1977

What are you going to do with the array? As you will have all found data in the gameScore Object available you can do from there whatever you want to do.

var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
   (gameScore: PFObject!, error: NSError!) -> Void in
if error == nil && gameScore != nil {
  println(gameScore)

  for singleScore in gameScore{
       println(singleScore) // this is the single result
       println(singleScore.objectId)
       println(singleScore["anyColName"])
  }

} else {
println(error.userInfo) // returns more details
  }
 }

Regarding your question:

var myArray: NSMutableArray! = NSMutableArray()

var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
  (gameScore: PFObject!, error: NSError!) -> Void in
if error == nil && gameScore != nil {

     println(gameScore)
     var temp: NSArray = gameScore as NSArray
     self.myArray = temp.mutableCopy() as NSMutableArray // now you have all results in an array

} else {
println(error.userInfo)
  }
 }

Upvotes: 1

Related Questions