swift - iOS: Passing Parameters to private Framework while Initializing a UIViewController -
i trying create custom framework can use across apps. when instantiate first viewcontroller
framework in app, pass in 2 parameters.
import uikit public class newvc: uiviewcontroller { public var startcolor: string? public var endcolor: string? public required init(startcolor: string, endcolor: string) { self.startcolor = startcolor self.endcolor = endcolor super.init(nibname: "sb", bundle: nil) } public required init?(coder adecoder: nscoder) { super.init(coder:adecoder) } }
now, trying instantiate newvc
in appdelegate
:
import newvcframework //... let vc = newvc(startcolor:"00ff33a", endcolor:"ff0c756") let s = uistoryboard(name: "sb", bundle: nsbundle(forclass: vc)) //i error on line above points @ vc self.window?.rootviewcontroller = s.instantiateinitialviewcontroller()
below error get:
error: cannot convert value of type 'newvc' expected argument type 'anyclass' (aka 'anobject.type')
you passing newvc
instance uistoryboard
init method, expect class. use newvc.self
instead.
also, if use storyboard, init?(coder adecoder: nscoder)
called instead of custom init. can provide startcolor
, endcolor
values after view controller instance creation
code below should fix problem:
import newvcframework //... let s = uistoryboard(name: "sb", bundle: nsbundle(forclass: newvc.self)) let vc = s.instantiateinitialviewcontroller() !newvc // call init?(coder adecoder: nscoder) newvc vc.startcolor = "00ff33a" vc.endcolor = "ff0c756" self.window?.rootviewcontroller = vc
Comments
Post a Comment