Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 279
ndbroadbent Avatar asked Nov 14 '14 21:11

ndbroadbent


People also ask

How do you stop an infinite loop in Swift?

I was able to halt my loop by typing the iteration variable setting (that would stop the loop) somewhere else like in a text editor then right click pasting the text into the loop. In your case, right-click pasting l = 0 right before the last bracket should work.

Should you call super viewDidLoad?

viewDidLoad is called after the view is loaded into memory and the outlets are set. Since we override viewDidLoad , we should call super. The reason for this is the UIViewController is not in our control and there could be some setup performed there, and this is really important.

What is super viewDidLoad in Swift?

super is used to call up to your superclass when you override a method. For instance, viewDidLoad is declared in UIViewController. You have a subclass of UIViewController, say MenuViewController, or whatever you've called it.

What is infinite loop in Swift?

Infinite loops are program loops that continue effectively forever. In Swift, they look like this: while true { print("I'm alive!") } print("I've snuffed it!")


1 Answers

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.

like image 159
nloko Avatar answered Sep 22 '22 19:09

nloko