Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Interface Builder crashes when components are used on Storyboard #8

Closed
OrlSan opened this issue May 22, 2019 · 3 comments · Fixed by #9
Closed

Interface Builder crashes when components are used on Storyboard #8

OrlSan opened this issue May 22, 2019 · 3 comments · Fixed by #9

Comments

@OrlSan
Copy link
Contributor

OrlSan commented May 22, 2019

Hi!

I'm adding the OfficeUIFabric pod as described on the README.md and trying to use the components included into this library, but the Xcode's Interface Builder designer crashes if I use a custom class for a button changing it to MSButton.

The minimal reproduction of the error is contained on this repository https://github.com/OrlSan/officeuifabric-sb-demo

Although the application is actually compiling and running the Interface Builder is displaying a blank canvas just containing the base UIViewController frames, but nothing else:

Captura de Pantalla 2019-05-22 a la(s) 16 25 04

Xcode is displaying the Issue message Main.storyboard: error: IB Designables: Failed to render and update auto layout status for ViewController (BYZ-38-t0r): The agent crashed

The Diagnostic report found on ~/Library/Logs/DiagnosticReports is pointing the error as the following:

Application Specific Information:
CoreSimulator 587.35 - Device: iPhone 8 (72039265-FC19-42F2-BCF0-99B04E1058F5) - Runtime: iOS 12.2 (16E226) - DeviceType: iPhone 8
/Users/orlando/Desktop/OfficeUIFabric Demo/Pods/OfficeUIFabric/OfficeUIFabric/Controls/MSButton.swift: 27: 12: Fatal error: Use of unimplemented initializer 'init(frame:)' for class 'OfficeUIFabric.MSButton'

The full crash log is here: IBDesignablesAgent-iOS_2019-05-22-161443_d4nger.crash.txt

What I've tried

As fas as I'm understanding the MSButton class (subclass of UIButton) is crashing the designer because the init(frame:) initializer is not implemented. I actually tried to change the source code and added the initializer so the MSButton implementation will include the following:

    @objc public init(style: MSButtonStyle = .secondaryOutline) {
        self.style = style
        super.init(frame: .zero)
        initialize()
    }

    // Added this initializer
    @objc public override init(frame: CGRect) {
        super.init(frame: frame)
        initialize()
    }

    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initialize()
    }

But again Xcode is displaying an empty canvas and the error is Main.storyboard: error: IB Designables: Failed to render and update auto layout status for BNInitialViewController (BYZ-38-t0r): Failed to load designables from path (null)

I don't know if the implementation of the initializer is the correct way to address this issue because the IB is not displaying the canvas anyway. Seems like an issue with the Autolayout resolution or something related.

Additional information

Xcode: Version 10.2.1 (10E1001)
macOS version: macOS Mojave Version 10.14.5
Pod version: OfficeUIFabric (~> 0.2.0)

I appeciate your help on this Issue, and if you have any questions please let me know.

Thanks!

@OrlSan
Copy link
Contributor Author

OrlSan commented May 23, 2019

I had a second view on the problem and I think the solution is actually add the init(frame:) initializer to the MSButton class. Maybe the second error I reported on this Issue was due to the build not being cleaned. What I just did is:

  • Take the demo project where the error is replicated https://github.com/OrlSan/officeuifabric-sb-demo
  • Clean the build on Xcode (Command + Shift + K) and close the project
  • Change the Podfile source to git to the fork I just did, pointing to the fix-ib-crash-msbutton branch:
    pod 'OfficeUIFabric', :git => 'https://github.com/OrlSan/ui-fabric-ios.git', :branch => 'fix-ib-crash-msbutton'
    This implementation is only adding the init(frame:) initializer. See: OrlSan@06193ae
  • Run pod update and open the project again.

After this the application is running as expected (just like before this changes) but the Interface Builder is not crashing and is actually showing the button with the expected MSButton style:

Captura de Pantalla 2019-05-22 a la(s) 19 46 53

I think this solution might work, so I'd be happy to know your opinion and maybe I can open a PR.

@vladfilyakov
Copy link
Contributor

Hi Orlando

Thank you for reporting this issue and doing an investigation. Implementing init(frame:) might be a fix for it and then we will also have to convert init(style:) to a convenience initializer that should call a new init(frame:). You can create a PR for this change or we can fix it ourselves - you choice. Let me know what you decide.

Thanks,
Vlad

@OrlSan
Copy link
Contributor Author

OrlSan commented May 23, 2019

Hi Vlad.

I think I can implement the required init(frame:) and also the conversion for the init(style:) initializer. I'll work on this and then can open the PR.

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants