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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -