Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Input and output container in Swift #87

Open
onmyway133 opened this issue Oct 17, 2017 · 1 comment
Open

How to use Input and output container in Swift #87

onmyway133 opened this issue Oct 17, 2017 · 1 comment

Comments

@onmyway133
Copy link
Owner

This is a very nifty trick from ios-oss which was built around MVVM pattern. It uses protocol to define input and output, and a container protocol to contain them. Take https://github.com/kickstarter/ios-oss/blob/1f5643f6a769995ccd1bb3826699745e64597ab7/Library/ViewModels/LoginViewModel.swift for example

public protocol LoginViewModelInputs {

}

public protocol LoginViewModelOutputs {

}

public protocol LoginViewModelType {
  var inputs: LoginViewModelInputs { get }
  var outputs: LoginViewModelOutputs { get }
}

public final class LoginViewModel: LoginViewModelType, LoginViewModelInputs, LoginViewModelOutputs {
  public var inputs: LoginViewModelInputs { return self }
  public var outputs: LoginViewModelOutputs { return self }
}

Look how LoginViewModel conforms to 3 protocols. And when you access its input or output properties, you are constrained to only LoginViewModelInputs and LoginViewModelOutputs

@MarcSteven
Copy link

Great blog

@onmyway133 onmyway133 changed the title Learning from Open Source: Input and output container How to use Input and output container in Swift May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants