Search code examples
iosswiftxcodeinterface-builder

Xcode / InterfaceBuilder: Why aren't IBOutlets and IBActions declared in the baseclass not available in the subclass?


Say I have a class like this:

class MyViewModeledController<ViewModel: FeatureViewModeling>: UIViewController {

  @IBOutlet weak var headingLabel: UILabel?    
  @IBOutlet weak var flipFaceButton: UIButton?
  @IBOutlet weak var swipeFromRightGesture: UISwipeGestureRecognizer?
  @IBOutlet weak var swipeFromLeftGesture: UISwipeGestureRecognizer?

  var viewModel: ViewModel!
  
  // etc.
}

When I now create a concreteSubclass:

class MySpecificViewModeledController: MyViewModeledController<MySpecificViewModel> {
   // etc.
}

When in interface builder, none of the declared outlets or actions appear in the Outlets list in the Inspector pane.

Does anyone know why / a workaround for this?


Solution

  • This could have already been answered here: https://stackoverflow.com/a/54838186/421797

    It relates to having generic aspects of your class.

    The workaround would be to declare the properties as weak var (no IBOutlet), then in viewDidLoad of your subclass, assign them from some outlets you've created in your subclass.