ios - Swift: could not find an overload for conversion that accepts supplied argument -
if set argument nil, error appears. code this:
func addchild(childtoadd: uiviewcontroller, childtoremove: uiviewcontroller) { if (childtoremove != nil) { childtoremove.view.removefromsuperview() } var frame = childtoadd.view.frame cgrect frame.size.width = view.frame.size.width; frame.size.height = view.frame.size.height; childtoadd.view.frame = frame view.addsubview(childtoadd.view) } override func viewdidload() { super.viewdidload() addchild(firstviewcontroller, childtoremove: nil) //could not find overload conversion accepts supplied argument } as can see, should not set nil in there, should set into. it's working in objective-c.
your childtoremove parameter defined uiviewcontroller, not optional so cannot nil
try :
func addchild(childtoadd: uiviewcontroller, childtoremove: uiviewcontroller?) { to allow nil value sec parameter, , don't forget need disclose optional before using (using if let great way so) :
if allow childcontroller = childtoremove { childcontroller.view.removefromsuperview() } ios swift
No comments:
Post a Comment