ios - Fetching subclassed objects from Parse -
in our project, have class called attendee
, inherits pfobject
. run pfquery
fetches list of pfobjects, want store global attendee
array. below code array , our query:
var attendees: [attendee] = []
query.findobjectsinbackgroundwithblock { (objects: [anyobject]?, error: nserror?) -> void in if( error == nil ) { attendees = objects as! [attendee] } else { println( error ) } }
however, when check contents of attendees array in debugger, empty. using debugger, checked objects array returned findobjectsinbackgroundwithblock
, , there objects being fetched.
i've attached attendee
class definition below.
class attendee: pfobject, pfsubclassing { override class func initialize() { var oncetoken : dispatch_once_t = 0; dispatch_once(&oncetoken) { self.registersubclass() } } class func parseclassname() -> string { return "attendee" } }
why typecast , copy attendees not working correctly? developing on swift 1.2 , xcode 6.3
you have register custom object in appdelegate:
attendee.registersubclass()
just before parse initialization parse.setapplicationid("xxx", clientkey: "xxx")
if didn't, have init pfquery attendee's class name:
let query = pfquery(classname: attendee.parseclassname()) query.fromlocaldatastore() //if data locally stored query.findobjectsinbackgroundwithblock { .. }
these steps worked me.