How do you pass data from one ViewController to the next with TyphoonStoryboard?

I have the most basic storyboard powered application.

Screenie

We have controllers UINavigationController

and view A and B.

A has a text box where the user must enter their name. When the user touches the button, it goes to B, showing "Hello [NAME]!"

How to pass user entered name from A to B using Typhoon?

With Typhoon, I believe it allows me to avoid using it -prepareForSegue:sender:

, which is just evil from a DI perspective because it requires a connection between what would otherwise be completely unrelated View Controllers. (for example viewControllerB.nameToDisplay = self.textField.text;

)

+3


source to share


1 answer


A nice feature of Typhoon is the ability to use your assemblies as a factory interface that mixes static and temporary dependencies, thus avoiding the pattern of creating a custom factory. This function is called Runtime Arguments . However, since Storyboards are used to emit view controllers, it is not possible to use them:

  • Runtime arguments as the storyboard interface has no idea about it.
  • Initialization injection, as VCs emitted from storyboard use initWithCoder

Something else you can do is create a mutable model object in your scoped assembly TyphoonScopeWeakSingleton

- (Person *)storyboardModel
{
    return [TyphoonDefinition withClass:[Person class] 
        configuration:^(TyphoonDefinition *definition) {

        definition.scope = TyphoonScopeWeakSingleton;
    }];
}

      

You can then inject this into the top-level controller and any subsequent children on that stack. When this stack pops up over time, the model object will also be cleared.




Because the Storyboard view managers you create work best with just property dependencies, you can use this approach in conjunction with Typhoon autoscroll macros (still private, but available on the host computer). This saves time creating registration rules and connecting to the assembly:

@interface INFWelcomeController : UIViewController <INFWelcomeViewDelegate>

    @property (nonatomic, strong) InjectedClass(Person) model;
    @property (nonatomic, strong) InjectedProtocol(WebClient) client;

@end

      

Automatic posting will also be available for test integration cases.

0


source







All Articles