问题
I'm working on an iOS app written in Swift. I have a subclass of UITabBarController, and then a nested subclass:
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. But it crashes when I archive the app and send it to my phone with 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?
Am I doing something wrong here? Or is this a bug in Swift?
回答1:
Are you using New Relic in your app? (I'm guessing from all those NRMA__voidParamHandler references that you are.) I had this exact problem. I disabled the New Relic SDK and builds downloaded from Testflight stopped crashing. I haven't reported a bug yet, but you/I/we probably should.
回答2:
with the addition of swift all the sweet dynamic function look-ups objective-c has is done away. To get that functionality back you'll need to add the "dynamic" declaration flag to all methods that New Relic instruments.
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
回答3:
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. This leads me to believe that you have some errors somewhere on your system. I suggest doing a few things...
- Cleaning your build cmd+alt+shift+k && deleting the app on your phone.
- Closing Xcode then deleting your derived data. (If you haven't done this before I can expand on how to do it.)
- 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.
Also make sure the bundle ID is registered correctly and all is well server-side on Test Flight. I can't imagine why it would cause a loop but this is a strange situation so let's see what happens. :^)
来源:https://stackoverflow.com/questions/26939195/im-getting-an-infinite-loop-with-swift-when-calling-super-viewdidload-in-two