wire-ios_legacy icon indicating copy to clipboard operation
wire-ios_legacy copied to clipboard

Study: Use type erasure to make CallPermissionsConfiguration Equatable

Open billypchan opened this issue 4 years ago • 0 comments

What's new in this PR?

Issues

(This is a study of type erasure not necessary to merge) In CallInfoViewControllerInput, we wrote a isEqual method to compare 2 CallInfoViewControllerInput to act a s == method of Equatable. It works but:

  • it is long
  • easy to forgot update if new properties are added to the protocol
  • 2 different object conforms CallInfoViewControllerInput can be equal (This protocol is written for Mocking CallInfoConfiguration, so we need compare a mock and real object)

Causes

From the comment: // Workaround to make the protocol equatable, it might be possible to conform CallInfoConfiguration // to Equatable with Swift 4.1 and conditional conformances. Right now we would have to make // the CallInfoRootViewController generic to work around the Self requirement of // Equatable which we want to avoid.

With Swift 5 it is still not possible to make CallInfoViewControllerInput conforms Equatable due to same compiler error.

Solutions

Use type erasure to solve it. ref: https://khawerkhaliq.com/blog/swift-protocols-equatable-part-two/

  1. Conform CallInfoConfiguration to Equatable
  2. It requires CallInfoConfiguration member permissions, mediaManager and callState also Equatable. So we need to make them not a protocol type and conforms Equatable
  3. Create AnyCallPermissionsConfiguration, AnyAVSMediaManagerInterface and AnyCallStateExtending as a wrapper of them
  4. Add isEqual method to above protocol, and add default implementation to the extensions (where Self: Equatable)

Discuss

  • [ ] Is it worth to apply the change? These protocols are only conformed by 2 struct/class and one of them is Mock.

billypchan avatar Oct 11 '21 13:10 billypchan