Swiftmessages: Crash when trying to load a custom NIB

Created on 8 Oct 2018  路  6Comments  路  Source: SwiftKickMobile/SwiftMessages

      let myView : MessageView = try! SwiftMessages.viewFromNib(named: "MandateCell") // crash
      var config = SwiftMessages.defaultConfig
      config.duration = .forever
      config.presentationStyle = .bottom
      config.dimMode = .gray(interactive: true)
      SwiftMessages.show(config: config, view: myView)

this leads to a fatal error. Am I doing something wrong?

Most helpful comment

@iamsanketray123 the wrong step is probably this one: "selected the File's owner and added the class"
You shouldn't set your class in the "File's owner" but in the View
screen shot 2018-10-08 at 19 09 41

All 6 comments

You should probably change the MessageView type with your custom type like this:

let myView: MandateCell = try! SwiftMessages.viewFromNib(named: "MandateCell")

If this doesn't fix your issue try catching and printing the error like this:

do {
    let myView: MessageView = try SwiftMessages.viewFromNib(named: "MandateCell")
} catch {
    print("Error: \(error.localizedDescription)")
}

That way you can investigate the crash further.

You should probably change the MessageView type with your custom type like this:

let myView: MandateCell = try! SwiftMessages.viewFromNib(named: "MandateCell")

If this doesn't fix your issue try catching and printing the error like this:

do {
    let myView: MessageView = try SwiftMessages.viewFromNib(named: "MandateCell")
} catch {
    print("Error: \(error.localizedDescription)")
}

That way you can investigate the crash further.

I tried putting everything in the do try block and i get this for error.localizedDescription : The operation could not be completed (SwiftMessages.SwiftMessagesError error 0)

I created a new class class AddAlternateBank: MessageView { }
Created AddAlternateBank.xib file. selected the File's owner and added the class. Is that the right approach?

My guess is you haven't included your nib file in your app's target. However, it is hard for me to guess are you issue since you didn't post the crash's call stack.

@iamsanketray123 the wrong step is probably this one: "selected the File's owner and added the class"
You shouldn't set your class in the "File's owner" but in the View
screen shot 2018-10-08 at 19 09 41

That worked @gcharita .Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shukaka picture shukaka  路  5Comments

Khalphion picture Khalphion  路  4Comments

lixiang1994 picture lixiang1994  路  6Comments

fruitcoder picture fruitcoder  路  6Comments

lohenyumnam picture lohenyumnam  路  3Comments