Why am I getting the error "class ... must be registered with registerSubclass before using Parse" when I register a subclass?

After upgrading from iOS parse-library-1.6.3 to parse-library 1.7.5, I get the following error in the queryForTable of one of my PFQueryTableViewControllers:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The class Appname.AttendingModel must be registered with registerSubclass before using Parse.'

      

However, I register the subclass in my application: didFinishLaunchingWithOptions: using this code:

    AttendingModel.initialize()
    Parse.enableLocalDatastore()
    Parse.setApplicationId(Config.parseAppId, clientKey: Config.parseClientKey)

      

The initialization method AttendingModel looks like this:

override class func initialize() {
    var onceToken : dispatch_once_t = 0;
    dispatch_once(&onceToken) {
        self.registerSubclass()
    }
}

      

and the parse class name is also set:

class func parseClassName() -> String {
    return "Attending"
}

      

I have verified that the line self.registerSubclass()

in my method initialize

is called when the application starts, but I still get the error.

I must add that I am using Xcode 6.4 and working on iOS 8.4.

Here's the full stack trace of the error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The class Appname.AttendingModel must be registered with registerSubclass before using Parse.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000108354c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000107fedbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000108354b9d +[NSException raise:format:] + 205
    3   Appname                             0x00000001060cb9f0 +[PFObject query] + 120
    4   Appname                             0x000000010607fe73 _TFC8Appname 12UsersTableVC13queryForTablefS0_FT_CSo7PFQuery + 131
    5   Appname                             0x00000001060800c2 _TToFC8Appname 12UsersTableVC13queryForTablefS0_FT_CSo7PFQuery + 34
    6   Appname                             0x000000010613fac5 -[PFQueryTableViewController loadObjects:clear:] + 106
    7   Appname                             0x000000010613f3b7 -[PFQueryTableViewController viewDidLoad] + 59
    8   Appname                             0x000000010607fb3d _TFC8Appname 12UsersTableVC11viewDidLoadfS0_FT_T_ + 61
    9   Appname                             0x000000010607fde2 _TToFC8Appname 12UsersTableVC11viewDidLoadfS0_FT_T_ + 34
    10  UIKit                               0x0000000108c211d0 -[UIViewController loadViewIfRequired] + 738
    11  UIKit                               0x0000000108c213ce -[UIViewController view] + 27
    12  Appname                             0x0000000106097e13 _TFC8Appname 7UsersVC11viewDidLoadfS0_FT_T_ + 1347
    13  Appname                             0x0000000106098392 _TToFC8Appname 7UsersVC11viewDidLoadfS0_FT_T_ + 34
    14  UIKit                               0x0000000108c211d0 -[UIViewController loadViewIfRequired] + 738
    15  UIKit                               0x0000000108c213ce -[UIViewController view] + 27
    16  UIKit                               0x0000000108c46257 -[UINavigationController _startCustomTransition:] + 633
    17  UIKit                               0x0000000108c5237f -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
    18  UIKit                               0x0000000108c52ece -[UINavigationController __viewWillLayoutSubviews] + 43
    19  UIKit                               0x0000000108d9d6d5 -[UILayoutContainerView layoutSubviews] + 202
    20  UIKit                               0x0000000108b709eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    21  QuartzCore                          0x0000000106dceed2 -[CALayer layoutSublayers] + 146
    22  QuartzCore                          0x0000000106dc36e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    23  QuartzCore                          0x0000000106dc3556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    24  QuartzCore                          0x0000000106d2f86e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    25  QuartzCore                          0x0000000106d30a22 _ZN2CA11Transaction6commitEv + 462
    26  QuartzCore                          0x0000000106d310d3 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    27  CoreFoundation                      0x0000000108287ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    28  CoreFoundation                      0x0000000108287c00 __CFRunLoopDoObservers + 368
    29  CoreFoundation                      0x000000010827da33 __CFRunLoopRun + 1123
    30  CoreFoundation                      0x000000010827d366 CFRunLoopRunSpecific + 470
    31  GraphicsServices                    0x000000010a83ea3e GSEventRunModal + 161
    32  UIKit                               0x0000000108af08c0 UIApplicationMain + 1282
    33  Appname                             0x0000000105ffd9f7 main + 135
    34  libdyld.dylib                       0x000000010ba8c145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

      

Any idea what could be causing this? I am using the same registerSubclass mechanism for several other classes in this application and PFQueryTableViewControllers for other classes work fine.

+3


source to share


1 answer


The problem was my initialization function in the AttendingModel class. Using dispatch_once_t as a local var in a function does not serve to ensure that the subclass is registered exactly once, and the constant re-registration of the subclass seemed to cause problems for Parse.

Changing the initialization function to look like this fixed the problem:



private static var onceToken : dispatch_once_t = 0

override class func initialize() {
    dispatch_once(&onceToken) {
        self.registerSubclass()
    }
}

      

0


source







All Articles