4

we have a UI Library in Swift that contains our company UI elements for iOS Apps (there are some xibs, some storyboards and some swift code).

We have decided to add the support for swift package manager for this lib (before was added with Cocoapods) and there are some crashes whenever there is an IBOutlet connection between a xib file and swift code, or when there is a connection between a UIViewController in a storyboard and the class of that UIViewController in swift.

The same code with Cocoapods work perfectly, we only have those crashes when we install the library with swift package manager. We are using the bundle: Bundle.module.

Anyone has some similar crashes? Ideas?

user1458259
  • 139
  • 1
  • 5

2 Answers2

2

The app will crash with "Thread 1: EXC_BAD_ACCESS (code=1, address=x)" error if the Module name in the storyboard inspector does not match with the SwiftPM Product name. In my case, I faced this error after renaming the package name, because I forgot to change the Module name to correct one in the storyboard.

enter image description here

Amirca
  • 143
  • 1
  • 8
  • Hi @Amirca did you do this change only on the `File's Owner` property or for every UI element define in your XIBS, I notice some UI Controls don't allow me to add the module and some do. I think for example a `UILabel` declared in the XIBS does not allow me to define the `Module` – Idelfonso Gutierrez Jan 10 '22 at 16:06
  • 1
    Hello @IdelfonsoGutierrez, you have to do this change in every custom (subclass) UI element you have used in XIB—every element should have a correct module name—also in the XIB itself. Remember, UILable is the standard component in UIKit so it has its own module (UIKit) and you can not set a module for it. – Amirca Jan 11 '22 at 19:27
0

Not sure if this is the way to go but i was able to fix this by overriding the ViewControllers init forcing it to use the module bundle where the .xib is.

public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nil, bundle: Bundle.module)
}
Deitsch
  • 1,610
  • 14
  • 28