djcj
djcj

Reputation: 149

Get PFObject at index with swift

I have a list (self.stepsList) with three PFObject in it (casted from AnyObject).

I can loop through and print their attributes such as order, steps, pace, id etc, which have been previously fetched from Parse. For example:

if let list = self.stepsList as? [PFObject] {

    for object in list {
        let steps = object["steps"] as! Int
        var stepsAsString = String(steps)
        println("You walked: \(stepsAsString)")
    }
}

I can however not find a solution to fetch an object at specific index from stepsList or list. How do I do that?

Upvotes: 0

Views: 379

Answers (1)

YMonnier
YMonnier

Reputation: 1429

Normally you can do this :

for index in 0..<list.count {
     let steps = list[index]["steps"] as! Int
     var stepsAsString = String(steps)
     println("You walked: \(stepsAsString)")
}

So you can get the object with an index like this

self.stepsList[0] as! PFObject

I don't know if this will help you

Ysee

Upvotes: 1

Related Questions