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

Learning from Open Source: Input and output container #87

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

Comments

Projects
None yet
2 participants
@onmyway133
Owner

onmyway133 commented Oct 17, 2017

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

This comment has been minimized.

MarcSteven commented Jan 8, 2018

Great blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment