Search code examples
iosxcodeswiftinterface-builderwatchkit

All IBOutlets are nil in my main scene


On a Watch app, all my @IBOutlet variables are nil during the willActivate in my main scene.

I have a page-based application, and the other scenes are working fine, but my main scene finds all @IBOutlet to be nil. The weirdest part is that it was working fine until at some point, I don't know why, everything started to be nil.

I tried setting them to either weak or not, but this didn't change anything. They are not custom elements, only WKInterfaceLabel, WKIntefaceGroup and things like that.

The declarations are like this:

@IBOutlet weak var gamesTable: WKInterfaceTable!
@IBOutlet weak var livesGroup: WKInterfaceGroup!
@IBOutlet weak var livesLabel: WKInterfaceLabel!
@IBOutlet weak var coinsLabel: WKInterfaceLabel!
@IBOutlet weak var livesTimer: WKInterfaceTimer!

They seem correctly linked in Xcode, and I tried cleaning/restarting Xcode:

Xcode outlet links screenshot


Solution

  • I found the reason why all this was happening. It is very specific to the Apple Watch.

    Basically, my elements were not "installed" on 38mm Apple Watch. At one point, I had set my Xcode to 42mm Apple Watch because I wanted to tweak some things in this specific size, and I ended moving groups around and so on.

    What happened is that all the things I changed didn't happen in 38, so back in 38 everything was here, but the "installed" checkbox wasn't checked, and the scene was basically empty on a 38mm Apple Watch, which I hadn't noticed.