ios - Exception while registering subclass with Parse -
i have class called attendee
inherits pfobject
. in applicationdidfinishlaunching()
method, register subclass so:
func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { attendee.initialize() parse.enablelocaldatastore() parse.setapplicationid(objectmanager.appid, clientkey: objectmanager.clientkey) getdata() return true } func getdata() { //create query var attendeequery = attendee.query() attendeequery?.fromlocaldatastore() .frompinwithname(cachekeys.attendeeskey) .wherekey("conference", equalto: objectmanager.currentconf) //register background task var bgtask = uibackgroundtaskinvalid bgtask = uiapplication.sharedapplication().beginbackgroundtaskwithexpirationhandler({ () -> void in uiapplication.sharedapplication().endbackgroundtask(bgtask) bgtask = uibackgroundtaskinvalid println("attendees loader expiration handler called") }) //run query attendeequery?.findobjectsinbackgroundwithblock({ (cachedattendees: [anyobject]?, error:nserror?) -> void in if error != nil { println(error) return } ... uiapplication.sharedapplication().endbackgroundtask(bgtask) }) }) }
however, when run code, exception @ line var attendeequery = attendee.query()
. exception says need register attendee
subclass before use it. don't understand why saying that, register right beforehand. below attendee
class definition.
class attendee: pfobject, pfsubclassing { var name:string { return self["name"] as! string } ... override class func initialize() { var oncetoken : dispatch_once_t = 0; dispatch_once(&oncetoken) { self.registersubclass() } } class func parseclassname() -> string { return classes.attendee } }
the exception:
*** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'the class medconf.attendee must registered registersubclass before using parse.' *** first throw call stack: (0x1835002d8 0x194d240e4 0x183500218 0x1001e21d0 0x1001e1fac 0x100135d88 0x100138af0 0x1000e43e0 0x1000e4580 0x187fb3190 0x1881ca854 0x1881cd208 0x1881cb778 0x18bd093c8 0x1834b827c 0x1834b7384 0x1834b59a8 0x1833e12d4 0x187fac43c 0x187fa6fac 0x1000e7b48 0x1953a2a08)
i had same problem when upgraded parse's ios sdk 1.7.5 1.6.3. problem in initialize function, looked same yours.
using dispatch_once_t local var in function doesn't serve purpose of ensuring subclass registered once; noticed putting breakpoint on registersubclass() call in initialize function being called many times. constant re-registering of subclass apparently causing problems new version of parse sdk.
changing initialize function fixed problem:
private static var oncetoken : dispatch_once_t = 0 override class func initialize() { dispatch_once(&oncetoken) { self.registersubclass() } }
Comments
Post a Comment