为什么我可以得到Cannot convert value of type [AnyObject]! to expected argument type.
我试图加载nib到视图控制器。
func loadNibNamed(name: String!, owner: AnyObject!, options: [NSObject : AnyObject]!) -> [View1]!{
NSBundle.mainBundle(loadNibNamed("View1", owner: self, options: nil)).lastObject
}
我认为这是正确的代码在Swift2.0
NSBundle.mainBundle()。loadNibNamed("View1", owner: self, options: nil).last
lastObject是用于Swift1.2的,现在在swift2.0中不可用,请使用last。
要使用它,你可以把它转换成UIView
试试这个:
func loadNibNamed(name: String, owner: AnyObject, options: [NSObject : AnyObject]) -> [AnyObject] {
return NSBundle.mainBundle().loadNibNamed(name, owner: owner, options: options)
}