在Xcode 13 beta 5构建之前,应用程序一直运行良好。
突然,在视图控制器中的init代码行中得到这个错误:
init(dataProvider: DataProvider) {
self.dataProvider = dataProvider
super.init(style: .plain)
dataProvider.delegate = self
}
该代码在Xcode 12中运行良好,现在没有任何更改就中断了:
‘'NSInternalInconsistencyException',原因:'UIViewController丢失了初始化过程中填充的初始特征集合。这是一个严重的错误,可能是在调用UIViewController初始化程序之前访问视图控制器上的属性或方法引起的。视图控制器:’
我搜索了一下,只有找到一个模糊的线程在这个问题上,但没有多大帮助。
有时,放置一个断点并插入允许它在不崩溃的情况下工作,所以在引擎盖下似乎存在某种布局、竞争条件,但是我很难调试。我试着睡一觉,但不起作用。
关于如何调试这一点的任何和所有的建议都是值得赞赏的。现在,我无法获得更多的信息,以便调试。如果你知道造成这种情况的原因,或者在哪里寻找,我将感谢你的投入。
下面是错误堆栈跟踪:
*** First throw call stack:
(
0 CoreFoundation 0x00007fff203fc8a8 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff2019ebe7 objc_exception_throw + 48
2 Foundation 0x00007fff207501c9 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
3 UIKitCore 0x00007fff248310ed UIViewControllerMissingInitialTraitCollection + 188
4 UIKitCore 0x00007fff24835616 -[UIViewController traitCollection] + 155
5 UIKitCore 0x00007fff24824392 -[UITableViewController dealloc] + 196
6 App Dev 0x000000010e4f5680 $s05AppLaB027MyViewController
C14paymentMethods13selectedIndex5offer8delegateACSaySo16AppPaymentMethodCG_SiAA5Offer_pAA08CheckoutcD8Delegate_pSgtcfc + 368
7 App Dev 0x000000010e4f5726 $s05AppLaB027MyViewController
C14paymentMethods13selectedIndex5offer8delegateACSaySo16AppPaymentMethodCG_SiAA5Offer_pAA08CheckoutcD8Delegate_pSgtcfcTo + 102
8 App Dev 0x000000010e289291 -[CartViewController showPaymentMethodPickerWithPaymentMethods:] + 385
9 App Dev 0x000000010e289055 __59-[CartViewController showPaymentMethodPickerOrEntryForm]_block_invoke + 245
10 App Dev 0x000000010e7075ae $sSo16AppServiceResultVSo7NSArrayCSgSo7NSErrorCSgIeyByyy_ABSaySo16AppPaymentMethodCGSgs5Error_pSgIegygg_TR + 222
11 App Dev 0x000000010e707246 $sSo17AppAccountServiceC05AppLaD0E19fetchPaymentMethods11forListType7refresh09preferredF6Method10completionSo17AppRequestReceipt_pSgAC0fmiJ0O_S2bySo16AppServiceResultV_SaySo010AppPaymentM0CGSgs5Error_pSgtcSgtFyAN_ArTtcfU_ + 630
12 App Dev 0x000000010e707333 $sSo17AppAccountServiceC05AppLaD0E19fetchPaymentMethods11forListType7refresh09preferredF6Method10completionSo17AppRequestReceipt_pSgAC0fmiJ0O_S2bySo16AppServiceResultV_SaySo010AppPaymentM0CGSgs5Error_pSgtcSgtFyAN_ArTtcfU_TA + 35
13 App Dev 0x000000010e580474 $sSo16AppServiceResultVSaySo16AppPaymentMethodCGSgs5Error_pSgIegygg_ABSo7NSArrayCSgSo7NSErrorCSgIeyByyy_TR + 212
14 App Dev 0x000000010e39bcad __79-[AppAccountV3DAO fetchPaymentMethodsRefresh:preferredPaymentMethod:withBlock:]_block_invoke + 45
15 libdispatch.dylib 0x0000000110c18a18 _dispatch_call_block_and_release + 12
16 libdispatch.dylib 0x0000000110c19bfc _dispatch_client_callout + 8
17 libdispatch.dylib 0x0000000110c28366 _dispatch_main_queue_callback_4CF + 1195
18 CoreFoundation 0x00007fff2036a555 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
19 CoreFoundation 0x00007fff20364db2 __CFRunLoopRun + 2772
20 CoreFoundation 0x00007fff20363dfb CFRunLoopRunSpecific + 567
21 GraphicsServices 0x00007fff2cbb5cd3 GSEventRunModal + 139
22 UIKitCore 0x00007fff24fee193 -[UIApplication _run] + 928
23 UIKitCore 0x00007fff24ff2bfb UIApplicationMain + 101
24 App Dev 0x000000010e267120 main + 96
25 dyld 0x0000000110654e1e start_sim + 10
26 ??? 0x0000000000000001 0x0 + 1
27 ??? 0x0000000000000001 0x0 + 1
)
发布于 2021-09-09 15:58:57
在注释了大量代码之后,我开始得到一个新的错误:
致命错误:类‘PaymentPickerViewController’使用未实现的初始化器‘init(样式:)’
进一步研究一下这种行为,我们似乎有一个objc初始化扩展。我相信在这个Xcode 13中,objc代码会被破坏,不会“看到”对初始化程序的根调用。
我们最初的init代码路径是:
@objc extension PaymentPickerViewController {
convenience init() {
dataProvider = DataProvider()
self.init(dataProvider: dataProvider)
}
}
init(dataProvider: DataProvider) {
self.dataProvider = dataProvider
super.init(style: .plain)
}
该修补程序显式地覆盖了我们希望从超级用户处使用的快速init:
override init(style: UITableView.Style) {
super.init(style: .plain)
self.dataProvider = DataProvider()
}
这迫使objc看到正确的init,然后它就能工作了。
我担心最初的错误,我张贴是非常误导,所以希望这有助于任何人谁遇到这个问题。
发布于 2021-10-05 19:23:15
简单描述:对于基于目标C的实现,可以将对象方法转换为类方法.
在xcode13
转基因种子上报告了以下错误。错误日志:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIViewController is missing
its initial trait collection populated during initialization. This is
a serious bug, likely caused by accessing properties or methods on the
view controller before calling a UIViewController initializer. View
controller: <MyViewController: 0x7fa5ae2356c0>'
对于下面的init method
- (instancetype)initWithModel:(MyModel *)myModel {
MyViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"MyViewController"];
vc.model = myModel;
return vc;
}
init
以下列方式从另一个View Controller
调用。
// Before - invoking object method -- Results in the error
MyViewController *viewController = [[MyViewController alloc] initWithModel:testModel];
// After - invoking Class method
MyViewController *viewController = [MyViewController initWithModel:testModel];
为了解决这个问题,我将init
方法转换为一个类方法。
+ (instancetype)initWithModel:(MyModel *)myModel {
MyViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"MyViewController"];
vc.model = myModel;
return vc;
}
https://stackoverflow.com/questions/69092599
复制相似问题