0

Why cam I getting the Cannot convert value of type [AnyObject]! to expected argument type. I am trying to load a nib into a view controller.

func loadNibNamed(name: String!, owner: AnyObject!, options: [NSObject : AnyObject]!) -> [View1]!{
    NSBundle.mainBundle(loadNibNamed("View1", owner: self, options: nil)).lastObject
}
Lorenzo
  • 3,293
  • 4
  • 29
  • 56
blee
  • 297
  • 4
  • 13

2 Answers2

0

I think this is right code in Swift2.0

NSBundle.mainBundle().loadNibNamed("View1", owner: self, options: nil).last

lastObject is for Swift1.2 and now it isn't available in swift2.0 use last instead.

And to use it , you can convert it into UIView.

Alex
  • 616
  • 4
  • 11
0

Try this:

func loadNibNamed(name: String, owner: AnyObject, options: [NSObject : AnyObject]) -> [AnyObject] {
        return NSBundle.mainBundle().loadNibNamed(name, owner: owner, options: options)
}
phuongle
  • 1,166
  • 11
  • 17
  • It's not placing the nib in the viewcontroller – blee Oct 08 '15 at 03:36
  • @blee: I just correct your code. Here is your reference http://stackoverflow.com/a/31957214/3614616 if you want to custom view from xib file – phuongle Oct 08 '15 at 03:51