简体   繁体   English

在两个嵌套的子类中调用super.viewDidLoad()时,我正在使用Swift进行无限循环

[英]I'm getting an infinite loop with Swift when calling super.viewDidLoad() in two nested subclasses

I'm working on an iOS app written in Swift. 我正在开发一个用Swift编写的iOS应用程序。 I have a subclass of UITabBarController, and then a nested subclass: 我有一个UITabBarController的子类,然后是一个嵌套的子类:

class HWTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        ...
    }
}

class MainTabBarController: HWTabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        ...
    }
}

This works fine in the iOS simulator, and even when I'm debugging the app on my iPhone. 这在iOS模拟器中运行良好,甚至在我在iPhone上调试应用程序时也是如此。 But it crashes when I archive the app and send it to my phone with TestFlight. 但是当我将应用程序存档并使用TestFlight将其发送到我的手机时,它会崩溃。

My crash logs are filled with this infinite loop: 我的崩溃日志充满了这个无限循环:

22  HDWR                           0x00145e10 @objc HDWR.MainTabBarController.viewDidLoad (HDWR.MainTabBarController)() -> () (MainTabBarController.swift:16)
23  HDWR                           0x00262867 NRMA__voidParamHandler
24  HDWR                           0x0014ea00 HDWR.HWTabBarController.viewDidLoad (HDWR.HWTabBarController)() -> () (HWTabBarController.swift:24)
25  HDWR                           0x00145e10 @objc HDWR.MainTabBarController.viewDidLoad (HDWR.MainTabBarController)() -> () (MainTabBarController.swift:16)
26  HDWR                           0x00262867 NRMA__voidParamHandler
27  HDWR                           0x0014ea00 HDWR.HWTabBarController.viewDidLoad (HDWR.HWTabBarController)() -> () (HWTabBarController.swift:24)
28  HDWR                           0x00145e10 @objc HDWR.MainTabBarController.viewDidLoad (HDWR.MainTabBarController)() -> () (MainTabBarController.swift:16)
29  HDWR                           0x00262867 NRMA__voidParamHandler
30  HDWR                           0x0014ea00 HDWR.HWTabBarController.viewDidLoad (HDWR.HWTabBarController)() -> () (HWTabBarController.swift:24)
31  HDWR                           0x00145e10 @objc HDWR.MainTabBarController.viewDidLoad (HDWR.MainTabBarController)() -> () (MainTabBarController.swift:16)
32  HDWR                           0x00262867 NRMA__voidParamHandler
33  HDWR                           0x0014ea00 HDWR.HWTabBarController.viewDidLoad (HDWR.HWTabBarController)() -> () (HWTabBarController.swift:24)

What's the voidParamHandler instruction, and why does it lead back to MainTabBarController.viewDidLoad ? 什么是voidParamHandler指令,为什么它会返回MainTabBarController.viewDidLoad

Am I doing something wrong here? 我在这里做错了吗? Or is this a bug in Swift? 或者这是Swift中的错误?

Are you using New Relic in your app? 你在你的应用程序中使用New Relic吗? (I'm guessing from all those NRMA__voidParamHandler references that you are.) I had this exact problem. (我猜测你所有那些NRMA__voidParamHandler引用。)我有这个确切的问题。 I disabled the New Relic SDK and builds downloaded from Testflight stopped crashing. 我禁用了New Relic SDK,从Testflight下载的版本停止了崩溃。 I haven't reported a bug yet, but you/I/we probably should. 我还没有报告过一个bug,但你/我/我们可能应该这样做。

with the addition of swift all the sweet dynamic function look-ups objective-c has is done away. 随着swift的加入,所有甜蜜的动态功能查找Objective-c已经完成了。 To get that functionality back you'll need to add the "dynamic" declaration flag to all methods that New Relic instruments. 要恢复该功能,您需要将“动态”声明标志添加到New Relic仪器的所有方法中。

Like this: 像这样:

class HWTabBarController: UITabBarController {
    override dynamic func viewDidLoad() {
        super.viewDidLoad()
        ...
    }
}

class MainTabBarController: HWTabBarController {
    override dynamic func viewDidLoad() {
        super.viewDidLoad()
        ...
    }
}

More details, including which functions this includes, here: https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/getting-started/enabling-swift-interaction-traces 更多细节,包括这些功能,包括: https//docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/getting-started/enabling-swift-interaction-traces

I just downloaded the repo, signed it on my own profile and everything seemed to work as you have it programmed. 我刚下载了回购邮件,在我自己的个人资料上签名,所有内容似乎都可以正常运行。 No infinite loop, no crashing. 没有无限循环,没有崩溃。 This is through Test Flight as well. 这也是通过Test Flight进行的。 This leads me to believe that you have some errors somewhere on your system. 这让我相信你的系统某处有一些错误。 I suggest doing a few things... 我建议做几件事......

  1. Cleaning your build cmd+alt+shift+k && deleting the app on your phone. 清理构建cmd + alt + shift + k &&删除手机上的应用程序。
  2. Closing Xcode then deleting your derived data. 关闭Xcode然后删除派生数据。 (If you haven't done this before I can expand on how to do it.) (如果你还没有这样做,我可以扩展如何做到这一点。)
  3. Registering it as a new app on test flight if practical. 如果可行的话,在测试航班上将其注册为新应用程序。

My idea is that it will help when you delete your derived data but I would do it all just so you know everything is clean. 我的想法是,当你删除你的派生数据时它会有所帮助,但我会这样做只是为了让你知道一切都很干净。 Again, I did not encounter this problem at any stage: simulator, direct install from Xcode or download via Test Flight. 同样,我在任何阶段都没有遇到过这个问题:模拟器,从Xcode直接安装或通过Test Flight下载。

Also make sure the bundle ID is registered correctly and all is well server-side on Test Flight. 还要确保捆绑ID已正确注册,并且所有在测试飞行中都是服务器端。 I can't imagine why it would cause a loop but this is a strange situation so let's see what happens. 我无法想象为什么它会导致循环,但这是一个奇怪的情况所以让我们看看会发生什么。 :^) :^)

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

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