0

I get an error while trying to cast a result from a PFQuery into the correct Subclass.

The error is swift_dynamicCastClassUnconditional

My code looks something like this:

let resellerQuery = Reseller.query()    // Reseller is a subclass of PFObject

resellerQuery.fromLocalDatastore()

resellerQuery.whereKey("name", equalTo: resellerName)

resellerQuery.getFirstObjectInBackgroundWithBlock({ (result: PFObject?, error) -> Void in

   if (error == nil) {
      let resellerObject = result as Reseller
   }
})

I get the error on the line where I create the resellerObject.

let resellerObject = result as Reseller

Do you have any ide what I'm doing wrong?

mugx
  • 9,869
  • 3
  • 43
  • 55
  • Is it a runtime error or compile error? This post might be helpful: http://stackoverflow.com/questions/26307335/swift-dynamiccastclassunconditional-issues-in-swift – Yoichi Tagaya Mar 16 '15 at 12:19
  • Did you do "4. Call [YourClass registerSubclass] before Parse setApplicationId:clientKey:. An easy way to do this is with your class' +load method in Objective-C or with +initialize in Swift."? – Bart de Ruijter Mar 16 '15 at 12:40
  • I have the `registerSubclass()` method in my initialize() method. `override class func initialize() { var onceToken : dispatch_once_t = 0; dispatch_once(&onceToken) { self.registerSubclass() } }` – Aaron Schmied Mar 16 '15 at 13:15

0 Answers0