ios - Overriding default initializer when using storyboards (Constructor Dependency Injection) -


the typical approach taken when 1 needs pass/share variables among view controllers (using storyboards) grab reference target viewcontroller in prepareforsegue: method , use property injection so:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if ([[segue identifier] isequaltostring:@"segue_name"])     {         // reference target view controller (optional casting)         destinationviewcontroller *vc = (destinationviewcontroller *)segue.destinationviewcontroller;          // pass objects/properties         vc.whateverobject = object; } 

}

the problem approach (as see in context of domain i'm dealing on current project) dependency on object being passed/injected not explicit.

though kind of freedom (being able inject dependencies after initialization) welcome in use cases flexibility required, of time prefer feeling of safety constructor injection provides.

especially in language objective-c passing around , sending messages nil allowed/common, hunting bugs forgot set property @ right point tiresome unit tests me up.

what i'd know if there way use custom initializer, 1 provide many arguments/dependencies need.

is there way can manually control initialization of segue.destinationviewcontroller?

as long know can not. if want custom initialization have without segues - using init, store destinationviewcontroller manually , whatever need pushviewcontroller or presentviewcontroller.

another drawback of using segue destinationviewcontroller recreated every time.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -