![](/img/trans.png)
[英]'The class PFUser must be registered with registerSubclass before using Parse.'
[英]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.