繁体   English   中英

为什么我在注册子类时遇到错误“类...必须在使用Parse之前注册registerSubclass”?

[英]Why am I getting the error “the class … must be registered with registerSubclass before using Parse” when I am registering the subclass?

从iOS parse-library-1.6.3升级到parse-library 1.7.5之后,我在我的一个PFQueryTableViewControllers的queryForTable中收到以下错误:

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

但是,我在应用程序中注册了子类:didFinishLaunchingWithOptions:,使用以下代码:

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

AttendingModel的initialize方法如下所示:

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

并且还设置了解析类名称:

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

我已经验证我的initialize方法中的self.registerSubclass()行是在应用程序启动时调用的,但我仍然收到错误。

我应该补充一点,我正在使用Xcode 6.4并在iOS 8.4上运行。

这是错误的完整堆栈跟踪:

*** 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

知道是什么原因引起的吗? 我在这个应用程序中使用相同的机制来注册其他几个类的子类,而其他类的PFQueryTableViewControllers都运行正常。

问题出在我的AttendingModel类的初始化函数中。 使用dispatch_once_t作为函数中的局部变量不能用于确保子类只注册一次,并且子类的常量重新注册显然会导致Parse出现问题。

更改初始化函数看起来像这样修复了问题:

private static var onceToken : dispatch_once_t = 0

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM