0

i'm casting an array of pfobject in PFQueryTableViewController, but got an error.. which is the corrent way?

override func objectsDidLoad(error: NSError?) {
    super.objectsDidLoad(error)

    var totalSeconds: Int = 0

    for record in objects as! [Record] {
        totalSeconds += Int(record.totalDuration)
    }

    navigationItem.prompt = MyUtility.stringFromSeconds(totalSeconds)
}

record must be an "Record" object conform to protocol PFSubclassing

Now, when the objects finish loading the debugger say error

fatal error: NSArray element failed to match the Swift Array Element type

TheMiloNet
  • 363
  • 2
  • 13

1 Answers1

0

I solved in this way:

override func objectsDidLoad(error: NSError?) {
    super.objectsDidLoad(error)

    var totalSeconds: Int = 0
    let records = objects as! [Record]

    for record in records{
        totalSeconds += Int(record.totalDuration)
    }

    navigationItem.prompt = MyUtility.stringFromSeconds(totalSeconds)
}

There is a faster way to do the same thing?

TheMiloNet
  • 363
  • 2
  • 13